RFR: JDK-8282776: Bad NullPointerException message when invoking an interface MethodHandle on a null receiver [v3]

Mandy Chung mchung at openjdk.java.net
Wed Mar 23 23:22:31 UTC 2022


On Wed, 23 Mar 2022 03:37:01 GMT, Mandy Chung <mchung at openjdk.org> wrote:

>> src/java.base/share/classes/java/lang/invoke/DirectMethodHandle.java line 424:
>> 
>>> 422:                     throw new IncompatibleClassChangeError(msg);
>>> 423:                 } else {
>>> 424:                     throw new NullPointerException("Cannot invoke " + member + " with null receiver");
>> 
>> Suggestion:
>> 
>>                     String msg = String.format("Cannot invoke %s with null receiver",
>>                                                member);
>>                     throw new NullPointerException(msg);
>
> Good catch.   Will update it.

I now reminded myself that java.base is built with -XDstringConcat=inline to avoid the bootstrap issue.   So the original patch should have no issue.  In any case, I updated the patch to use `String.format` to be consistent with the ICCE message formatting.

-------------

PR: https://git.openjdk.java.net/jdk/pull/7766


More information about the core-libs-dev mailing list