Bug 99428

Summary: [1.5][compiler] enum classes created without final accessFlag
Product: [Eclipse Project] JDT Reporter: Peter Shipton <Peter_Shipton>
Component: CoreAssignee: Kent Johnson <kent_johnson>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: daniel_megert
Version: 3.1   
Target Milestone: 3.1 RC3   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
enum test case
none
Fix the final bit issue.
none
This is the right patch
none
Patch for the test094
none
Simplified patch none

Description Peter Shipton CLA 2005-06-10 14:24:16 EDT
This problem occurs in Eclipse 3.1RC1.

Compile the following enum using Eclipse 3.1RC1, and Enum1 has the
accessFlags: 0x4021

Compile the enum using JDK 1.5 javac, and Enum1 has the accessFlags: 0x4031

The difference is the FINAL access flag.


public enum Enum1 {

	ONE,
	TWO;

public static void main(String[] args) throws Exception  {
	System.out.println(Integer.toHexString(Enum1.class.getModifiers()));
}
}
Comment 1 Olivier Thomann CLA 2005-06-10 16:59:15 EDT
I get 0x4001 using RC1 or any version of javac 1.5.
Comment 2 Peter Shipton CLA 2005-06-10 17:01:29 EDT
Created attachment 22842 [details]
enum test case

This is the test case that found the problem. The test passes on JDK when its
been compiled with javac.
Comment 3 Peter Shipton CLA 2005-06-10 17:07:52 EDT
This is the javac I'm using:

javac 1.5.0_03-ea

java version "1.5.0_03-ea"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_03-ea-b04)
Java HotSpot(TM) Client VM (build 1.5.0_03-ea-b04, mixed mode)

Comment 4 Philipe Mulet CLA 2005-06-13 06:39:02 EDT
+1 for RC3

Dani - would you pls cast a vote on it ? Our compiler isn't producing valid
files without it.
Comment 5 Dani Megert CLA 2005-06-13 06:42:57 EDT
+1 for 3.1 RC3.
Comment 6 Olivier Thomann CLA 2005-06-13 09:22:36 EDT
Indeed an enum type is implicitely final if none of its constants has a body.

So the first example:

public enum X {
	ONE, TWO
}

leads to a final bit set in the classfile.

Whereas the classfile for 

public enum X {

	ONE() {
		public String toString() {
			return "1";
		}
	},
	TWO;
}

doesn't have the final bit set.
Comment 7 Olivier Thomann CLA 2005-06-13 10:23:17 EDT
Created attachment 22923 [details]
Fix the final bit issue.
Comment 8 Olivier Thomann CLA 2005-06-13 14:19:06 EDT
Created attachment 22952 [details]
This is the right patch
Comment 9 Olivier Thomann CLA 2005-06-13 14:39:04 EDT
Created attachment 22953 [details]
Patch for the test094
Comment 10 Olivier Thomann CLA 2005-06-13 14:39:48 EDT
Created attachment 22954 [details]
Simplified patch
Comment 11 Kent Johnson CLA 2005-06-15 10:16:12 EDT
Added EnumTest test114
Comment 12 Olivier Thomann CLA 2005-06-16 14:14:52 EDT
Output is now:
// Compiled from X.java (version 1.5 : 49.0, super bit)
// Signature: Ljava/lang/Enum<LX;>;
public final enum X extends java.lang.Enum {
...

Verified using N20050616-0010 + JDT/Core HEAD