Bug 92165

Summary: [1.5][compiler] No compilation error on invalid construct
Product: [Eclipse Project] JDT Reporter: Zorzella Mising name <zorzella>
Component: CoreAssignee: JDT-Core-Inbox <jdt-core-inbox>
Status: RESOLVED DUPLICATE QA Contact:
Severity: normal    
Priority: P3    
Version: 3.1   
Target Milestone: 3.1.1   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description Zorzella Mising name CLA 2005-04-20 18:39:55 EDT
The following enum declares a static field, and then accesses it from a
non-static initializer. "javac" balks at this construct, and running an
application from within Eclipse that uses the enumeration throws a weird Exception.

*************************************

public enum ErrorEnum {

	UNKNOWN ();

    private static String error;
    
    {
        error = "error";
    }
    

}
*****************************

javac error is:

    ErrorEnum.java:10: illegal reference to static field from initializer

*******************************
Comment 1 Philipe Mulet CLA 2005-04-21 18:24:55 EDT
Unclear why this should be any different from:
public class X {
	static String other;
	static {
		other = "other";
	}
}

which is accepted just fine.
Comment 2 Zorzella Mising name CLA 2005-04-21 20:14:35 EDT
I also looked at it, baffled, for quite some time. It might be something
specific to the way enums are spec'ed (maybe the fine print in the language
specification). Rather than dive into it myself, I trusted that if a) javac
balks at it, and b) the java virtual machine throws a nasty error, then it's
quite likely invalid...

Zorzella
Comment 3 Philipe Mulet CLA 2005-04-22 02:30:31 EDT
What nasty error did you get running our generated classfile ? I did not get any.
Comment 4 Olivier Thomann CLA 2005-06-07 13:03:48 EDT
Tried with latest.
No error reported.
javac complains, but I could not understand why.
Comment 5 Philipe Mulet CLA 2005-07-19 12:15:56 EDT
Actually, javac is right here. One cannot refer to an enum constant within code
which is going to perform while it is getting initialized (enum constants are
triggering constructors/initializers).

Added GenericTypeTest#test791

*** This bug has been marked as a duplicate of 101713 ***
Comment 6 Philipe Mulet CLA 2005-07-19 12:16:38 EDT
Actually, regression test is: EnumTest#test121