Community
Participate
Working Groups
Build ID: M20090211-1700 Steps To Reproduce: The following sample code compiles in Eclipse 3.4.0 build I20080617-2000, but not in 3.4.2 build M20090211-1700: public enum BugTest { SAMPLE(TEST); private static final int TEST = 1; int x; BugTest(int x) { this.x = x; } } It fails with the error "Cannot reference a field before it is defined". More information: According to page 202 of the JLS: "One subtlety here is that, at run time, static variables that are final and that are initialized with compile-time constant values are initialized first." Therefore, the sample code should compile, since the forward reference is to a compile-time constant. (And, as I mentioned, it compiled in earlier versions of Eclipse.)
In fact the reference needs to be qualified in order to be used in a forward reference. So this code compiles fine: public enum X { SAMPLE(X.TEST); private static final int TEST = 1; int x; X(int x) { this.x = x; } } but the code in comment 0 should report an error. Now this doesn't solve the problem with 3.4.2 that has a bug. See bug 263877. *** This bug has been marked as a duplicate of bug 255452 ***
Yes, the code that you provided is actually the code that I meant to submit (with the qualified reference). That code still doesn't compile for me in 3.4.2. Is that case also covered by #255452?
(In reply to comment #2) > Is that case also covered by #255452? Now this is bug 263877 that has been fixed post 3.4.2. The fix is available in the 3.5 stream since 3.5M6.
According to the last comment in #263877, there should be a patch for the 3.4 stream for this issue. When will that be available through the "Search for Updates" feature?
No, there is a jar that provides this fix available on the JDT/Core update page. See http://www.eclipse.org/jdt/core/r3.4/index.php#UPDATES. This has to be applied through a feature patch or via an update site. There is no "official" Eclipse build post 3.4.2. I'll see if I can setup an update site on the JDT/Core page that would provide this update.
The patch doesn't work. The versions dialog lists the version for org.eclipse.jdt.core as 3.4.5.v_895_R34x, but I still get the same compiler errors. What's the correct way to install this patch?
I'm also compiling using compatibility level 1.6, and bug #263877 was marked as [1.5]. Was it also fixed for the 1.6 compiler?
Yes, this is fixed for any compliance level >= 1.5. I'll send you a patch and you'll tell me if it works for you.
As the comment 0 does not compile in Eclipse 3.4.2, this bug is rather a duplicate of bug 263877 rather than bug 255452. Hence, change the target accordingly... *** This bug has been marked as a duplicate of bug 263877 ***
Verified using build I20090313-0100 (aka 3.5M6)