If a superclass A has an instance class foo() and a subclass B extends A has a static method with the same name and signature (see example code below), JNI_GetMethodID stops the lookup once it finds a matching method from class B and throws NoSuchMethodException since B.foo is a static method.
class A {
protected void foo() {
System.out.println("A.foo");
}
}
class B extends A {
private static void foo() {
System.out.println("private static B.foo()");
}
}
javac will fail to compile the above and this requires patching the bytecode to get to this test case.
This is related to the issue reported at
http://weblog.ikvm.net/PermaLink.aspx?guid=cce26630-b8f3-4a05-b9d3-2426fb442385
Another issue when the subclass has a private "foo" instance method and its superclass also defines an instance "foo", the bytecode invocation of invokevirtual will ignore the private method and use the non-private foo method in the superclass.
The spec of JNI_GetMethodID should also be clarified whether it will ignore the private method in this case.
class A {
protected void foo() {
System.out.println("A.foo");
}
}
class B extends A {
private static void foo() {
System.out.println("private static B.foo()");
}
}
javac will fail to compile the above and this requires patching the bytecode to get to this test case.
This is related to the issue reported at
http://weblog.ikvm.net/PermaLink.aspx?guid=cce26630-b8f3-4a05-b9d3-2426fb442385
Another issue when the subclass has a private "foo" instance method and its superclass also defines an instance "foo", the bytecode invocation of invokevirtual will ignore the private method and use the non-private foo method in the superclass.
The spec of JNI_GetMethodID should also be clarified whether it will ignore the private method in this case.
- relates to
-
JDK-8027351 (ref) Private finalize method invoked in preference to protected superclass method
- Resolved
-
JDK-8027271 Verifier fails to catch a subclass overriding a final method with static method
- Closed