Bug 149042 - [1.5][compiler] Invalid compilation errors regarding Enum intializers
Summary: [1.5][compiler] Invalid compilation errors regarding Enum intializers
Status: RESOLVED DUPLICATE of bug 101713
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1.2   Edit
Hardware: PC Windows 2000
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-06-28 12:56 EDT by James Leone CLA
Modified: 2006-09-08 09:08 EDT (History)
0 users

See Also:


Attachments
Sample enum that should compile (150 bytes, text/x-java-source)
2006-06-28 12:58 EDT, James Leone CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
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