Bug 102213

Summary: [1.5][compiler] enum constants cannot be referenced inside enum constants initializer
Product: [Eclipse Project] JDT Reporter: Olivier Thomann <Olivier_Thomann>
Component: CoreAssignee: Philipe Mulet <philippe_mulet>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3    
Version: 3.1   
Target Milestone: 3.1.1   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description Olivier Thomann CLA 2005-06-29 17:08:51 EDT
The following code should be rejected, because the constant is not yet
initialized when referenced inside its initializer.

public enum X {
	A() {
		X a = A;

		void foo() {
			System.out.println(String.valueOf(a));
		}
	};
	abstract void foo();

	public static void main(String[] args) {
		A.foo();
	}
}

We accept it and return null at runtime.
Comment 1 Philipe Mulet CLA 2005-07-01 10:20:26 EDT
Detection for enum static field references inside initializer did not handle
enum constant body (direct superclass of declaringClass of field).

Comment 2 Philipe Mulet CLA 2005-07-01 10:20:40 EDT
Added EnumTest#test120.
Fixed
Comment 3 Maxime Daniel CLA 2005-08-09 10:45:08 EDT
Verified in 3.2 M1 with build I20050808-2000.
javac does not complain (at least javac 1.5.0_04-ea), but it should according
to JLS 8.9 - in this case, self reference of A in its constructor.
Comment 4 David Audel CLA 2005-09-26 10:39:21 EDT
Verified using M20050923-1430 for 3.1.1