-
Bug
-
Resolution: Fixed
-
P4
-
9
-
b106
MethodHandles.Lookup.findVirtual() throws IllegalAccessException if the method MH is being created for is private and declared in an interface.
Example:
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
public interface PrivateInterfaceMethodLookupTest {
public static void main(String[] args) throws NoSuchMethodException, IllegalAccessException {
MethodHandles.lookup()
.findVirtual(PrivateInterfaceMethodLookupTest.class, "m", MethodType.methodType(void.class));
}
private void m() {}
}
Output:
Exception in thread "main" java.lang.IllegalAccessException: no such method: PrivateInterfaceMethodLookupTest.m()void/invokeInterface
at java.lang.invoke.MemberName.makeAccessException(MemberName.java:869)
at java.lang.invoke.MemberName$Factory.resolveOrFail(MemberName.java:990)
at java.lang.invoke.MethodHandles$Lookup.resolveOrFail(MethodHandles.java:1382)
at java.lang.invoke.MethodHandles$Lookup.findVirtual(MethodHandles.java:858)
at PrivateInterfaceMethodLookupTest.main(PrivateInterfaceMethodLookupTest.java:7)
Caused by: java.lang.IncompatibleClassChangeError: private interface method requires invokespecial, not invokeinterface: method PrivateInterfaceMethodLookupTest.m()V
at java.lang.invoke.MethodHandleNatives.resolve(Native Method)
at java.lang.invoke.MemberName$Factory.resolve(MemberName.java:962)
at java.lang.invoke.MemberName$Factory.resolveOrFail(MemberName.java:987)
... 3 more
Example:
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
public interface PrivateInterfaceMethodLookupTest {
public static void main(String[] args) throws NoSuchMethodException, IllegalAccessException {
MethodHandles.lookup()
.findVirtual(PrivateInterfaceMethodLookupTest.class, "m", MethodType.methodType(void.class));
}
private void m() {}
}
Output:
Exception in thread "main" java.lang.IllegalAccessException: no such method: PrivateInterfaceMethodLookupTest.m()void/invokeInterface
at java.lang.invoke.MemberName.makeAccessException(MemberName.java:869)
at java.lang.invoke.MemberName$Factory.resolveOrFail(MemberName.java:990)
at java.lang.invoke.MethodHandles$Lookup.resolveOrFail(MethodHandles.java:1382)
at java.lang.invoke.MethodHandles$Lookup.findVirtual(MethodHandles.java:858)
at PrivateInterfaceMethodLookupTest.main(PrivateInterfaceMethodLookupTest.java:7)
Caused by: java.lang.IncompatibleClassChangeError: private interface method requires invokespecial, not invokeinterface: method PrivateInterfaceMethodLookupTest.m()V
at java.lang.invoke.MethodHandleNatives.resolve(Native Method)
at java.lang.invoke.MemberName$Factory.resolve(MemberName.java:962)
at java.lang.invoke.MemberName$Factory.resolveOrFail(MemberName.java:987)
... 3 more
- relates to
-
JDK-8138883 5.4.3.5: Clarify that method handle resolution of REF_invokeInterface is private-aware
-
- Closed
-