Bug 239225 - [1.5][compiler] False Compiler error when referencing statics in enum - initialisation
Summary: [1.5][compiler] False Compiler error when referencing statics in enum - initi...
Status: VERIFIED INVALID
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.5   Edit
Hardware: Macintosh Mac OS X - Carbon (unsup.)
: P3 normal (vote)
Target Milestone: 3.5 M1   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-07-02 07:41 EDT by Sebastian Graf CLA
Modified: 2009-05-07 03:32 EDT (History)
1 user (show)

See Also:


Attachments
Testcase-Example (322 bytes, text/java)
2008-07-02 07:45 EDT, Sebastian Graf CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Sebastian Graf CLA 2008-07-02 07:41:36 EDT
Build ID: I20080617-2000

Steps To Reproduce:
1.Create an enum
2. Create a static member variable in this enum but do not initialize it
3. Initialize the static member in the private constructor. It's not working even if every compilance-setting is set at least to "warning".


More information:
See the example file Status.java attached. It's compiled on the commando line as well as on Eclipse 3.3
Comment 1 Sebastian Graf CLA 2008-07-02 07:45:10 EDT
Created attachment 106301 [details]
Testcase-Example

This file is compile on the commando line without any problems. With Eclipse 3.3 it's compiled as well, With Eclipse 3.4, unfortunately, a Compiler Error arises even if every JDK Compilance setting is set at most to "Warning"
Comment 2 Philipe Mulet CLA 2008-07-02 07:59:54 EDT
This is the expected behavior. Basically, we were missing to detect an error in 3.3.2, this was signaled as bug 228109, and fixed for 3.4RC1.

So in essence, this is invalid code which we used to accept by mistake.

Marking as invalid, since this is the expected behavior.
Comment 3 Philipe Mulet CLA 2008-07-02 08:03:26 EDT
Added GenericTypeTest#test1364
Comment 4 Philipe Mulet CLA 2008-07-02 09:12:11 EDT
Actually, regression tests are EnumTest#test162-163.

Note that the following would work fine:
---------------------------------------
import java.util.HashMap;
import java.util.Map;

enum Status {
	GOOD((byte) 0x00), BAD((byte) 0x02);
	private byte value;
	private static Map<Byte, Status> mapping;
	private Status(final byte newValue) {
		this.value = newValue;
	}
	static {
		Status.mapping = new HashMap<Byte, Status>();
		for (Status s : values()) {
			Status.mapping.put(s.value, s);
		}
	}
}
Comment 5 Kent Johnson CLA 2008-08-06 12:56:41 EDT
Verified for 3.5M1 using I20080805-1307