RFR: JDK-8281003 - MethodHandles::lookup throws NPE if caller is null
Alan Bateman
alanb at openjdk.java.net
Mon Feb 14 18:15:08 UTC 2022
On Mon, 14 Feb 2022 18:03:45 GMT, Mandy Chung <mchung at openjdk.org> wrote:
>> src/java.base/share/classes/java/lang/invoke/MethodHandles.java line 121:
>>
>>> 119: Class<?> c = Reflection.getCallerClass();
>>> 120: if (c == null) {
>>> 121: throw new IllegalCallerException();
>>
>> Throwing ICE is probably okay here, I just wonder if there is any practical advantage to having it return publicLookup instead, e.g. is there any scenario where a JNI attached thread might want to invoke a method with a Lookup parameter?
>
> `MethodHandles::publicLookup` can be called instead to get a public Lookup to invoke a method with a Lookup parameter. The dilemma here is whether the API should be made null-caller friendly or using a proper API `MethodHandles::publicLookup` for such case.
You are right. If a JNI attached thread with no Java frames wants a Lookup then it can invoke publicLookup. I think the proposal here is good.
-------------
PR: https://git.openjdk.java.net/jdk/pull/7447
More information about the build-dev
mailing list