-
Type:
CSR
-
Resolution: Approved
-
Priority:
P4
-
Component/s: hotspot
-
behavioral
-
minimal
-
Java API
-
Implementation
Summary
IllegalAccessError will not be thrown when resolving a default method named registerNatives() method. Previously IAE was thrown because private native Object::registerNatives method was selected in method resolution.
Problem
Consider this Java program:
public class RegisterNatives {
interface I {
default public void registerNatives() {
System.out.println("I");
}
}
static class A implements I { }
public static void main(String... args) {
A varA = new A();
varA.registerNatives();
}
}
Previously, this would throw an IllegalAccessError due the resolution logic giving priority to a private registerNatives method declared in Object rather than the default method in interface I:
Exception in thread "main" java.lang.IllegalAccessError: class RegisterNatives tried to access private method 'void java.lang.Object.registerNatives()'
(RegisterNatives is in unnamed module of loader 'app'; java.lang.Object is in module java.base of loader 'bootstrap')
at RegisterNatives.main(RegisterNatives.java:6)
When the private Object::registerNatives method is removed, the method resolution A::registerNatives will resolve successfully to the default method I::registerNatives.
Solution
The behavioral change does not have any compatibility risk since the previous behavior results in an error.
Specification
No spec change.
- csr of
-
JDK-8232613 Move Object.registerNatives into HotSpot
-
- Resolved
-