JDK-8013527 : calling MethodHandles.lookup on itself leads to errors
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang.invoke
  • Affected Version: 9
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2013-04-30
  • Updated: 2022-11-29
  • Resolved: 2021-10-28
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 18
18 b22Fixed
Related Reports
Blocks :  
Relates :  
Relates :  
Description
Use MHs.lookup to look itself up.  The resulting MH is broken.  See attached test case, or the following snippet:

 Lookup lookup = lookup();
 lookup.findStatic(lookup.lookupClass(), "say", methodType(void.class, String.class)).invokeExact("hello, world");
 MethodHandle MH_lookup2 = lookup.findStatic(MethodHandles.class, "lookup", methodType(Lookup.class));
 // Next line gets IAE: illegal lookupClass: class java.lang.invoke.MethodHandleImpl$BindCaller$T/471910020
 Lookup lookup2 = (Lookup) MH_lookup2.invokeExact();

Suggested fix:  Special-case the caller binding logic for lookup.

Consider doing this for any other hyper-sensitive @CallerSensitive method which looks at more than its caller class loader.
Comments
Changeset: c6339cb8 Author: Mandy Chung <mchung@openjdk.org> Date: 2021-10-28 18:32:50 +0000 URL: https://git.openjdk.java.net/jdk/commit/c6339cb8a255d387bb182ad20dd69f3d460cf1ed
28-10-2021