Bug 102213 - [1.5][compiler] enum constants cannot be referenced inside enum constants initializer
Summary: [1.5][compiler] enum constants cannot be referenced inside enum constants ini...
Status: VERIFIED FIXED
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: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-06-29 17:08 EDT by Olivier Thomann CLA
Modified: 2005-09-26 10:39 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 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