Bug 81454 - enum values() method fails when called from static initializer
Summary: enum values() method fails when called from static initializer
Status: RESOLVED DUPLICATE of bug 78321
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Linux
: P3 critical (vote)
Target Milestone: 3.1 M4   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-12-16 15:11 EST by Jeff Norris CLA
Modified: 2004-12-16 15:25 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jeff Norris CLA 2004-12-16 15:11:26 EST
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.
Comment 1 Olivier Thomann CLA 2004-12-16 15:25:34 EST

*** This bug has been marked as a duplicate of 78321 ***