Skip to main content

NullPointerException on java.util.EnumMap. : Java 6 SE

1 reply [Last post]
Joined: 2006-12-18

I've been working on an SMTP client in Java. That is coded and finished, and I'm trying to extend it to ESMTP now. As I expected when running a first trial, it threw an exception, but it came from a very unexpected angle, namely from EnumMap's constructor.

I have an enum Capabilities declared that represents ESMTP server capabilities that are transmitted on a EHLO. It is declared static in following manner:

public class ESMTPSocket extends SMTPSocket {<br />
    public static enum Capabilities {<br />
<p>    // ...class code goes here...<br />

When the socket attempts to parse the server's output after connecting, it creates an EnumMap to do so:

protected EnumMap serverCapabilities;</p>
<p>private void fillServerCapabilities() {<br />
    serverCapabilities = new EnumMap(Capabilities.class);<br />

...where it throws a NullPointerException. In particular, it seems that it cannot find the key universe belonging to this particular enum. The problem originates somewhere within sun.misc.SharedSecrets, but I haven't its source code available.

public EnumMap(Class keyType) {<br />
    this.keyType = keyType;<br />
    keyUniverse = getKeyUniverse(keyType);<br />
    vals = new Object[keyUniverse.length]; // throws NullPointerException with no message<br />

I've tried Googling on associated keywords but found no match or even a hint that this problem exists, so I'm assuming I'm doing something subtly wrong. Strangely, I use enums (but not EnumMap) in other projects and there haven't been any problems there.

I've attempted to declare the enum as non-static, but no difference there; exact same exception. Removing the generics from serverCapabilities' declaration and definition did nothing either (except generate compiler warnings).

The program can iterate over the enum's values perfectly before EnumMap's constructor is even called, so the values should exist:

static {<br />
    for (Capabilities e : Capabilities.values()) {<br />
        System.out.println("value: " + e);<br />
    }<br />

"java -version" gives me "1.6.0-b105".

Does anyone see what I'm doing wrong here?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2006-12-18

Doing the compilation by hand--instead of using NetBeans 5.5--seems to do the trick. Which is strange, since in either case I'm using the same javac.exe, I believe.

But at any rate, the code's fine, and so are the libraries. It's probably an IDE hitch.