RFR: JDK-8282776: Bad NullPointerException message when invoking an interface MethodHandle on a null receiver [v2]
Mandy Chung
mchung at openjdk.java.net
Fri Mar 11 22:52:42 UTC 2022
On Fri, 11 Mar 2022 22:49:25 GMT, Mandy Chung <mchung at openjdk.org> wrote:
>> A simple patch to call `Objects.requireNonNull(recv)` for an explicit null receiver check rather than NPE thrown by `Object::getClass`. The message of NPE generated by JEP 358 (Helpful NullPointerExceptions) is supposed to be helpful but not in this case.
>
> Mandy Chung has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains three additional commits since the last revision:
>
> - Move the null check after isInstance check
> - Merge branch 'master' of https://github.com/openjdk/jdk into JDK-8282776
> - JDK-8282776: Bad NullPointerException message when invoking an interface MethodHandle on a null receiver
I did a quick sanity run of the reflection microbenchmarks. I eyeball the numbers and don't spot any difference.
OTOH, since the `isInstance` check covers the null check, moving the null check inside the exception case is a better fix.
-------------
PR: https://git.openjdk.java.net/jdk/pull/7766
More information about the core-libs-dev
mailing list