On Fri, 11 Mar 2022 22:49:25 GMT, Mandy Chung <mch...@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

src/java.base/share/classes/java/lang/invoke/DirectMethodHandle.java line 424:

> 422:                     throw new IncompatibleClassChangeError(msg);
> 423:                 } else {
> 424:                     throw new NullPointerException();

Since we know which `member` this is trying to invoke, the **NPE** can be 
constructed with a [JEP 358](https://openjdk.java.net/jeps/358)‑style message.

src/java.base/share/classes/java/lang/invoke/DirectMethodHandle.java line 456:

> 454:                     throw new IncompatibleClassChangeError(msg);
> 455:                 } else {
> 456:                     throw new NullPointerException();

Since we know which `member` this is trying to invoke, the **NPE** can be 
constructed with a [JEP 358](https://openjdk.java.net/jeps/358)‑style message.

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

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

Reply via email to