Bug 77349

Summary: [compiler] ClassFormatError when accessing clone() or finalize() methods from an interface
Product: [Eclipse Project] JDT Reporter: Olivier Thomann <Olivier_Thomann>
Component: CoreAssignee: Kent Johnson <kent_johnson>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3    
Version: 3.1   
Target Milestone: 3.1 M6   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description Olivier Thomann CLA 2004-10-31 14:09:42 EST
Compiling the following code and running it result in a ClassFormatError.

Exception in thread "main" java.lang.ClassFormatError: Method access$0 in class
I has illegal modifiers: 0x1008
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
        at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
        at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
        at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
        at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)

interface I extends Cloneable {
    class Inner {
        Object bar(I i) {
            try {
                return i.clone();
            } catch (CloneNotSupportedException e) {
                return null;
            }
        }
    }
}

public class X implements I {
	public static void main(String[] args) {
	}
}

Compiled with javac 1.5.0, this returns:
X.java:5: cannot find symbol
symbol  : method clone()
location: interface I
                return i.clone();
                        ^
1 error

jikes 1.22 reports:

Found 1 semantic error compiling "C:/tests_sources/X.java":

     5.                 return i.clone();
                               ^-------^
*** Semantic Error: The method "java.lang.Object clone() throws
java.lang.CloneNotSupportedException;" only has protected access in
"java.lang.Object"
, so it is not accessible from an interface.
Comment 1 Olivier Thomann CLA 2005-02-11 14:44:27 EST
Extracting the Inner class outside of the interface I works fine. We do report
an error.
We should never end up adding a synthetic method on an interface.
Comment 2 Kent Johnson CLA 2005-03-14 17:45:50 EST
Since 1.4 only public methods from Object are visible to an interface

Added test099 to Compliance_1_3/4/5
Comment 3 Olivier Thomann CLA 2005-03-30 18:53:37 EST
Verified in 20050330-0500