Bug 242885 - [1.5][compiler] Referring static field within enum constructor causes compiling error in Eclipse 3.4. And Eclipse 3.2, 3.3 and Javac(1.5) don't have this error!
Summary: [1.5][compiler] Referring static field within enum constructor causes compili...
Status: VERIFIED DUPLICATE of bug 228109
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.4   Edit
Hardware: PC Windows XP
: P3 blocker (vote)
Target Milestone: 3.5 M2   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-08-01 10:37 EDT by Raymond Ye CLA
Modified: 2008-09-15 09:01 EDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Raymond Ye CLA 2008-08-01 10:37:39 EDT
Build ID: I20080617-2000

Steps To Reproduce:
1.Create a java project and set 'Installed JRE'jdk150_12
2.Create an enum class with a static field(See examples in More information) 
3.Create a constructor and try to refer the static field, and a compiling error appears.
4.Detail error message: Cannot refer to the static enum field xxx with an initializer

More information:
/* The enum class can be successfully compiled by Eclipse 3.2, 3.3 and Javac(1.5) but fails compiling in Eclispe 3.4(Ganymede)
*/

package com.xxx.forms;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Raymondy
 *
 */
public enum FormId {
	T1P1("T1 P1"),
	T1P2("T1 P2"),
	T1P3("T1 P3"),
	T1P4("T1 P4"),
	UNKNOWN("Unknown");
	
	private String name;
	private static Map<String, FormId> formIds = new HashMap<String, FormId>();
	
	private FormId(String name) {
		this.name = name;
		FormId.formIds.put(name, this);
	}
	
	public String toString() {
		return name;
	}
	
	public static FormId getFormId(String formId) {
		return formIds.get(formId);
	}
}
Comment 1 Olivier Thomann CLA 2008-08-14 10:05:01 EDT
Closing as a dup of bug 228109.
This code should not compile. This was a bug in the Eclipse compiler and javac 1.5 that has been fixed.

*** This bug has been marked as a duplicate of bug 228109 ***
Comment 2 Jerome Lanneluc CLA 2008-09-15 09:01:24 EDT
Verified for 3.5M2 using I20080914-2000 that the error is still correctly reported.