Bug 156540

Summary: Compiler produces invalid bytecode for certain enum declarations
Product: [Eclipse Project] JDT Reporter: harding fela <hardingfela>
Component: CoreAssignee: Olivier Thomann <Olivier_Thomann>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3    
Version: 3.1.2   
Target Milestone: 3.3 M2   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
Proposed fix none

Description harding fela CLA 2006-09-07 11:51:26 EDT
The following code produces invalid bytecode:

<snip>
public class EnumBug {

    interface Interface {
        public int value();
    }
    
    public enum TheEnum implements Interface {
        ;
        
        TheEnum(int value) { this.value = value; }        
        public int value() { return value; }
        
        private int value;
    }
    
    public static void main(String[] args) {
        TheEnum x = null;
    }
}
</snip>

Error when executing: 
java.lang.ClassFormatError: Illegal class modifiers in class EnumBug: 0x4419
	at java.lang.ClassLoader.defineClass1(Native Method)
	at java.lang.ClassLoader.defineClass(Unknown Source)
	at java.security.SecureClassLoader.defineClass(Unknown Source)
	at java.net.URLClassLoader.defineClass(Unknown Source)
	at java.net.URLClassLoader.access$100(Unknown Source)
	at java.net.URLClassLoader$1.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(Unknown Source)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	at java.lang.ClassLoader.loadClassInternal(Unknown Source)
Exception in thread "main" 

---

The same code compiles / executes fine with the Sun JDK compiler.
Comment 1 Olivier Thomann CLA 2006-09-07 15:01:50 EDT
I'll investigate.
Comment 2 Olivier Thomann CLA 2006-09-07 15:53:32 EDT
We are wrong to set the abstract bit when the enum type has no enum constant.
This bit should be set only when some enum constants don't define the interface method.
Comment 3 Olivier Thomann CLA 2006-09-07 15:53:52 EDT
Created attachment 49656 [details]
Proposed fix
Comment 4 Olivier Thomann CLA 2006-09-07 21:04:36 EDT
Released for 3.3M2.
Fixed and released in HEAD.
Added regression test in org.eclipse.jdt.core.tests.compiler.regression.EnumTest#test137
Comment 5 Maxime Daniel CLA 2006-09-18 10:14:55 EDT
Verified for 3.3 M2 using build I20060918-0010.