JDK-8281003 : MethodHandles::lookup throws NPE if caller is null
  • Type: Sub-task
  • Component: core-libs
  • Sub-Component: java.lang.invoke
  • Affected Version: 7
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2022-01-31
  • Updated: 2022-02-23
  • Resolved: 2022-02-16
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 19
19 masterFixed
Related Reports
CSR :  
Description
Access checks are performed at the method handle creation time via the Lookup object against its lookup class.

If MethodHandles::lookup is invoked via JNI code with no caller frame, two possible options:
1. throw IllegalCallerException as no caller is available
2. return a public lookup (MethodHandles::publicLookup)

While it may look that returning a public lookup is JNI-friendly, I think the caller should call the proper API, i.e. MethodHandles::publicLookup, if public lookup is what they want.   Throwing IllegalCallerException would help the existing code to call the right API.
Comments
Changeset: 67763df4 Author: Tim Prinzing <tim.prinzing@oracle.com> Committer: Mandy Chung <mchung@openjdk.org> Date: 2022-02-16 20:09:46 +0000 URL: https://git.openjdk.java.net/jdk/commit/67763df4dce387da33da6d93d0f5d80e54cf8e5b
16-02-2022

A pull request was submitted for review. URL: https://git.openjdk.java.net/jdk/pull/7447 Date: 2022-02-11 20:32:46 +0000
11-02-2022

I implemented option 1. Tested on linux. Staged at https://github.com/tprinzing/jdk-1/tree/JDK-8281003. Will verify on windows and Mac before doing a pull request.
11-02-2022