MethodHandles.publicLookup().in() returns Lookup with no permissions?
Simone Bordet
simone.bordet at gmail.com
Tue Nov 24 18:21:41 UTC 2020
Hi,
testing the Jetty MethodHandle usages we encountered this situation:
.class org.openjdk.mh.Main
----
Class<?> klass = Main.class;
MethodHandles.Lookup lookup = MethodHandles.publicLookup().in(klass);
MethodHandle handle = lookup.findVirtual(klass, "test",
MethodType.methodType(String.class));
----
.module-info.java
----
module org.openjdk.mh {
exports org.openjdk.mh to com.acme;
}
----
findVirtual() throws:
java.lang.IllegalAccessException: symbolic reference class is not
accessible: class org.openjdk.mh.Main, from
org.openjdk.mh.Main/noaccess (module org.openjdk.mh)
Removing the "to" clause from the exports in module-info.java fixes the issue.
Seems that a class cannot get a MethodHandle on itself, the reason
being that org.openjdk.mh is selectively exported in module-info.java.
Is this intended behavior?
I would have expected that a class could always get a MethodHandle on itself.
I tested this with 11, 15, and 16+25, all fail.
I have a simple reproducer, and I can open an OpenJDK bug.
Thanks!
--
Simone Bordet
---
Finally, no matter how good the architecture and design are,
to deliver bug-free software with optimal performance and reliability,
the implementation technique must be flawless. Victoria Livschitz
More information about the jigsaw-dev
mailing list