From the Java Spec Report mailing list:
Perhaps JLS 9.2 is correct after all, that interfaces do NOT extend
Object from the language point of view (even if they do so from the VM
point of view), and that therefore interfaces do not have clone() or
finalize(). Both jikes and javac compile this example, but the
resulting .class file from either compiler causes the VM to throw a
VerifyError. But if the two compilers were to take JLS 9.2 at face
value, rather than implementing the suggestions of the spec report, this
would be a compile-time error.
$ cat Blah.java
class Blah {
public static void main(String[] args) {
I.Inner.bar(new I(){});
}
}
interface I {
class Inner {
static void bar(I i) {
try {
// An inner class has access to any protected members, but
// according to JLS 9.2, I has no protected members, so this
// reference to finalize should not compile.
i.finalize();
} catch (Throwable t) {
}
}
}
}
$ javac Blah.java
$ java Blah
Exception in thread "main" java.lang.VerifyError: (class: I$Inner,
method: bar signature: (LI;)V) Bad access to protected data
at Blah.main(Blah.java:3)
Perhaps JLS 9.2 is correct after all, that interfaces do NOT extend
Object from the language point of view (even if they do so from the VM
point of view), and that therefore interfaces do not have clone() or
finalize(). Both jikes and javac compile this example, but the
resulting .class file from either compiler causes the VM to throw a
VerifyError. But if the two compilers were to take JLS 9.2 at face
value, rather than implementing the suggestions of the spec report, this
would be a compile-time error.
$ cat Blah.java
class Blah {
public static void main(String[] args) {
I.Inner.bar(new I(){});
}
}
interface I {
class Inner {
static void bar(I i) {
try {
// An inner class has access to any protected members, but
// according to JLS 9.2, I has no protected members, so this
// reference to finalize should not compile.
i.finalize();
} catch (Throwable t) {
}
}
}
}
$ javac Blah.java
$ java Blah
Exception in thread "main" java.lang.VerifyError: (class: I$Inner,
method: bar signature: (LI;)V) Bad access to protected data
at Blah.main(Blah.java:3)
- duplicates
-
JDK-4526320 VerifyError when accessing protected method in interface
- Closed
-
JDK-4643104 interfaces improperly inherit protected members from object
- Closed
- relates to
-
JDK-4479715 compiler incorrectly rejects interface int clone();
- Closed