Bug 92165 - [1.5][compiler] No compilation error on invalid construct
Summary: [1.5][compiler] No compilation error on invalid construct
Status: RESOLVED DUPLICATE of bug 101713
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.1.1   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-04-20 18:39 EDT by Zorzella Mising name CLA
Modified: 2005-07-19 12:16 EDT (History)
0 users

See Also:


Attachments

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