Bug 81773 - JDK5.0 enum bug
Summary: JDK5.0 enum bug
Status: RESOLVED INVALID
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 M5   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-12-22 04:00 EST by Xavier Méhaut CLA
Modified: 2004-12-22 04:50 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Xavier Méhaut CLA 2004-12-22 04:00:38 EST
Hello,
I've found a bug in the processing of the enumerated types in JDK5.0 in Eclipse
3.1M4.
let the following definition :
enum EnumType {ONE, TWO, THREE);

The following expression is currently impossible :
EnumType currentType=EnumType.ONE;
switch (currentType) {
		case EnumType.ONE:
			break;
			
		case EnumType.TWO:
			break;
			
		case EnumType.THREE:
			break;

		default:
			break;
		}
Comment 1 Philipe Mulet CLA 2004-12-22 04:41:13 EST
Following code is illegal, since enum constants cannot be qualified in switch
cases. You should remove qualification, and it would still resolve as they are
resolved relatively to the switch expression type (EnumType here).

Also note that javac rejects this code, slightly wrong though (false duplicate
case labels):
>javac X.java -d ..\bin -Xlint
X.java:7: an enum switch case label must be the unqualified name of an
enumeration constant
                                case EnumType.ONE:
                                             ^
X.java:10: an enum switch case label must be the unqualified name of an
enumeration constant
                                case EnumType.TWO:
                                             ^
X.java:10: duplicate case label
                                case EnumType.TWO:
                                ^
X.java:13: an enum switch case label must be the unqualified name of an
enumeration constant
                                case EnumType.THREE:
                                             ^
X.java:13: duplicate case label
                                case EnumType.THREE:
                                ^
5 errors
public class X {
	enum EnumType {ONE, TWO, THREE}
	public static void main(String[] args) {
		EnumType currentType=EnumType.ONE;
		switch (currentType) {
				case EnumType.ONE:
					break;
					
				case EnumType.TWO:
					break;
					
				case EnumType.THREE:
					break;
		
				default:
					break;
				}
	}
}
Comment 2 Xavier Méhaut CLA 2004-12-22 04:46:08 EST
OK Philippe ;) Sun has not well done its job with enumeration. No switch for an
enumeration is silly imo :( 
thanks
regards
Xavier
Comment 3 Philipe Mulet CLA 2004-12-22 04:50:33 EST
You can switch on enum constants no problem. You cannot though qualify enum
constant references *only* in case labels (they may re-enable them later on).
You may still use static imports to grant access to them, or simply rely on the
fact that they are implicitly resolved relatively to the switch expression (so
not need to qualify individual constants); in your example, simply remove the
qualification and it will compile clean.