MethodHandles.lookup errors where publicLookup is ok

Chen Liang chen.l.liang at oracle.com
Tue Sep 2 15:56:26 UTC 2025


Hi Charlie,
This is definitely a bug in the JDK, but I need more investigation to ensure if the issue lies in Lookup or Proxy. I guess this might relate to the fact that proxy dynamic modules are open to java.base as an implementation artifact, because the public lookup has Object.class as its lookup class.

Since proxy has different module configurations depending on whether it has module-private or package-private interfaces, can you share a minimal setup where you can replicate this issue? I tried replicating on:

Proxy.newProxyInstance(ClassLoader.getSystemClassLoader(), new Class<?> []{Runnable.class}, (_, _, _) -> {return null;})

In jshell, and failed to replicate your failure with Lookup::accessClass.

Regards,
Chen Liang

________________________________
From: core-libs-dev <core-libs-dev-retn at openjdk.org> on behalf of Charles Oliver Nutter <headius at headius.com>
Sent: Tuesday, September 2, 2025 10:31 AM
To: core-libs-dev at openjdk.org <core-libs-dev at openjdk.org>
Subject: MethodHandles.lookup errors where publicLookup is ok

I've run into various versions of this situation and I wonder if my expectations about MethodHandles.lookup vs publicLookup are flawed.

This issue shows an IllegalAccessException "symbolic reference class is not accessible: class jdk.proxy4.$Proxy49" when using a Lookup produced by MethodHandles.lookup, but it works correctly when using publicLookup:

https://github.com/jruby/jruby/issues/8987#issuecomment-3245803956

My expectation would be that if publicLookup works, then lookup should also work. I've filed a similar issue in the past (unresolved) where I was forced to use publicLookup instead of lookup:

https://bugs.openjdk.org/browse/JDK-8313913

The error is similar here, but I'm not sure if it's related (module system should have been fully booted by the time of the JRuby failure).

If my expectation is correct, this is a new version of the bug and I can file an issue. It's happening at least as late as JDK 24.0.2.

If my expectation is not correct, please explain to me how I can know whether lookup will produce errors when publicLookup does not.

Charles Oliver Nutter
Architect and Technologist
Headius Enterprises
https://www.headius.com
headius at headius.com<mailto:headius at headius.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/core-libs-dev/attachments/20250902/76ef0a26/attachment-0001.htm>


More information about the core-libs-dev mailing list