Community
Participate
Working Groups
Calling an enum's values() method from a static initializer within that enum will fail in Eclipse 3.1 M3, but not in Sun's javac/java. As I explain below, this appears to be caused by a bug in Eclipse's java compiler. This simple program will reliably reproduce the error: public enum EnumTest { FOO, BAR; static { System.out.println("values = " + values()); } public static void main(String args[]) {} } If compiled with Sun's 1.5 javac and run with Sun's java, this program produces the following (correct) output: > values = [LEnumTest;@192d342 If compiled and run within Eclipse 3.1 M3, this program fails with the following exception: Exception in thread "main" java.lang.ExceptionInInitializerError Caused by: java.lang.NullPointerException at EnumTest.values(EnumTest.java:1) at EnumTest.<clinit>(EnumTest.java:6) This error is *also* produced if I run the class produced by Eclipse using Sun's 1.5 jre. Therefore, I believe that there is a bug in the Eclipse compiler. I speculate that the Eclipse compiler is placing the static initializer that it generates from the enumerated values *AFTER* that static initializer that I wrote. If this is the case, that's a bug - the static initializer produced from the enumerated values should appear first. Again, that's just speculation.
*** This bug has been marked as a duplicate of 78321 ***