Community
Participate
Working Groups
Given the following code: public enum TestEnum { FIRST, SECOND, THIRD; static { System.out.println("static"); try { System.out.println("values=" + values()); for (TestEnum t : values()) { System.out.println(" enum: " + t); } } catch(Exception e) { System.out.println(e); e.printStackTrace(); } } TestEnum() { System.out.println("TestEnum ctor"); } public static void main(String[] args) { } } I can compile it and run it on a Linux workstation, and it produces the following output: TestEnum ctor TestEnum ctor TestEnum ctor static values=[LTestEnum;@15ff48b enum: FIRST enum: SECOND enum: THIRD That's good. However, when I run this on Eclipse 3.1M3 on WinXP, I get a NullPointerException within values() on the line for (TestEnum t : values())
The bug is that the static initializer is processing user code first instead of generating the static init of the ENUM$VALUES synthetic field.
Created attachment 15783 [details] Apply on HEAD Proposed patch to generate all enum constants and the values synthetic field first and then the remaining part of the clinit.
Fixed and released in HEAD. Regression test added.
Verified that this test case can be compiled and run on Win XP using I200412140010.
*** Bug 81454 has been marked as a duplicate of this bug. ***