Bug 149042

Summary: [1.5][compiler] Invalid compilation errors regarding Enum intializers
Product: [Eclipse Project] JDT Reporter: James Leone <jleone>
Component: CoreAssignee: JDT-Core-Inbox <jdt-core-inbox>
Status: RESOLVED DUPLICATE QA Contact:
Severity: normal    
Priority: P3    
Version: 3.1.2   
Target Milestone: ---   
Hardware: PC   
OS: Windows 2000   
Whiteboard:
Attachments:
Description Flags
Sample enum that should compile none

Description James Leone CLA 2006-06-28 12:56:55 EDT
The attaced java file will compile when using javac with the following JDK:

java version "1.5.0_06"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05)
Java HotSpot(TM) Client VM (build 1.5.0_06-b05, mixed mode)

Eclipse gives the following compilation error:
Cannot refer to enum field State.INITIAL within an initializer

I have seen bugs similar to the topic (such as #101713) however the notes claim that bug was fixed in a September release of 3.1.1  This problem appears in the most recent 3.1.1 release and 3.1.2 release making me believe it is different.
Comment 1 James Leone CLA 2006-06-28 12:58:29 EDT
Created attachment 45479 [details]
Sample enum that should compile
Comment 2 Olivier Thomann CLA 2006-06-28 13:08:03 EDT
javac 6.0b88 agrees with us:
X.java:5: illegal reference to static field from initializer
            System.out.printf("After the %s constructor\n",INITIAL);
                                                           ^
1 error

but javac 1.5.0_07 compiles it fine. Looks like a bug has been fixed.
If you qualify the access, then it compiles fine with both Eclipse and javac 6.0b88.

public enum State {
    INITIAL ,
    OPENED {
        {
            System.out.printf("After the %s constructor\n",State.INITIAL);
        }
    }
}

Closing as dup of bug 101713.

*** This bug has been marked as a duplicate of 101713 ***
Comment 3 Olivier Thomann CLA 2006-06-28 13:10:43 EDT
Added regression test org.eclipse.jdt.core.tests.compiler.regression.EnumTest.test134