Bug 156540 - Compiler produces invalid bytecode for certain enum declarations
Summary: Compiler produces invalid bytecode for certain enum declarations
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1.2   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.3 M2   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-09-07 11:51 EDT by harding fela CLA
Modified: 2006-09-18 10:14 EDT (History)
0 users

See Also:


Attachments
Proposed fix (1.81 KB, patch)
2006-09-07 15:53 EDT, Olivier Thomann CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
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.