Bug 228109 - [1.5][compiler] Enum static field initializer in enum constructor failed to give compilation error
Summary: [1.5][compiler] Enum static field initializer in enum constructor failed to g...
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.3.2   Edit
Hardware: PC Windows XP
: P3 critical (vote)
Target Milestone: 3.4 RC1   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 242885 (view as bug list)
Depends on:
Blocks:
 
Reported: 2008-04-21 17:14 EDT by Jebastian Ponsekar CLA
Modified: 2008-08-14 10:05 EDT (History)
4 users (show)

See Also:


Attachments
Proposed patch (51.46 KB, patch)
2008-05-05 12:05 EDT, Philipe Mulet CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jebastian Ponsekar CLA 2008-04-21 17:14:00 EDT
Build ID: M20080221-1800

Steps To Reproduce:
1. Create an enum
2. Try to initialize static field inside enum constructor
3.As per jdk 1.6 specification it should fail but eclipse 3.3.2 didn't complain anything but javac compiler failed to compile when I try to compile in windows command line


More information:

public enum TestEnum {
	RED, GREEN, BLUE; 
    static int test = 0;  

    TestEnum() {
    	TestEnum.test=10;
    }
}

Current behavior in Eclipse 3.3.2 - No error
Correct behavior 
TestEnum.java:8: illegal reference to static field from initializer
    	TestEnum.test=10;
Comment 1 Jebastian Ponsekar CLA 2008-04-21 17:16:33 EDT
Jdk : jdk1.6.0_05
Eclipse : eclipse 3.3.2
Comment 2 Olivier Thomann CLA 2008-04-21 17:22:14 EDT
Reproduced with HEAD.
This used to be compiled fine with JDK1.5.0, but it now fails with JDK6.
Comment 3 Philipe Mulet CLA 2008-05-05 12:05:02 EDT
Added EnumTest#test153-161.

Support was incorrectly only considering implict static field accesses (see bug 101713). It should reject any such reference to an enum static field member.
Comment 4 Philipe Mulet CLA 2008-05-05 12:05:59 EDT
Created attachment 98656 [details]
Proposed patch
Comment 5 Philipe Mulet CLA 2008-05-05 12:07:09 EDT
Javac 5 does not detect non implicit references either; but this feels a bug as per JLS (i.e. will make the fix for all compliance levels).
Comment 6 Philipe Mulet CLA 2008-05-05 15:01:25 EDT
Released for 3.4RC1
Fixed
Comment 7 Kent Johnson CLA 2008-05-06 16:51:07 EDT
+1 for 3.4RC1
Comment 8 David Audel CLA 2008-05-13 07:03:30 EDT
Verified for3.4RC1 using I20080510-2000
Comment 9 Olivier Thomann CLA 2008-08-14 10:05:01 EDT
*** Bug 242885 has been marked as a duplicate of this bug. ***