-
Bug
-
Resolution: Unresolved
-
P4
-
7, 8
This is a very simple scenario. Just a class declaring a private method, and an interface declaring a public method with the same signature. It compiles without error. But the compile-time and runtime semantics don't match.
------
public class A {
private void m() { System.out.println("A.m"); }
public static void main(String... args) { B b = new C(); b.m(); }
}
public interface I {
public void m();
}
public abstract class B extends A implements I {
}
public class C extends B {
public void m() { System.out.println("C.m"); }
}
public class Test {
public static void main(String... args) { B b = new C(); b.m(); }
}
java Test
Exception in thread "main" java.lang.IllegalAccessError: tried to access method A.m()V from class Test
java A
A.m
------
Intuitively, a private method in A should be irrelevant, not affecting the behavior of other classes. Per JLS, I.m is a member of B, and that's what the invocations refer to. But per JVMS, a reference to 'B.m()V' resolves to A.m.
We could address the problem by changing resolution so that it ignores inherited private methods.
We could also address it by catching the conflict in the JLS and reporting an error (sort of like the "same erased signature" check).
------
public class A {
private void m() { System.out.println("A.m"); }
public static void main(String... args) { B b = new C(); b.m(); }
}
public interface I {
public void m();
}
public abstract class B extends A implements I {
}
public class C extends B {
public void m() { System.out.println("C.m"); }
}
public class Test {
public static void main(String... args) { B b = new C(); b.m(); }
}
java Test
Exception in thread "main" java.lang.IllegalAccessError: tried to access method A.m()V from class Test
java A
A.m
------
Intuitively, a private method in A should be irrelevant, not affecting the behavior of other classes. Per JLS, I.m is a member of B, and that's what the invocations refer to. But per JVMS, a reference to 'B.m()V' resolves to A.m.
We could address the problem by changing resolution so that it ignores inherited private methods.
We could also address it by catching the conflict in the JLS and reporting an error (sort of like the "same erased signature" check).
- blocks
-
JDK-8024806 invokeinterface: Remove IAE for selection of non-public method
-
- Open
-
- relates to
-
JDK-8098577 6.5: invokevirtual must specify selection when resolved method is in interface
-
- Resolved
-
-
JDK-8024647 Default method resolution with private superclass method
-
- Closed
-
-
JDK-8024804 Crash when InterfaceMethodref resolves to Object.registerNatives
-
- Closed
-
-
JDK-6691741 JLS membership algorithm is too strong for JVMS method resolution
-
- Closed
-
-
JDK-8043703 13.4.12: Adding methods can break binary compatibility
-
- Open
-
(1 relates to)