RFR: JDK-8282776: Bad NullPointerException message when invoking an interface MethodHandle on a null receiver [v3]
ExE Boss
duke at openjdk.java.net
Wed Mar 23 02:10:31 UTC 2022
On Tue, 22 Mar 2022 17:55:13 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 incrementally with one additional commit since the last revision:
>
> Add exception message
This needs to use `String.format(…)` in order to avoid circular dependencies in bootstraps on `java.lang.invoke.StringConcatFactory`.
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);
src/java.base/share/classes/java/lang/invoke/DirectMethodHandle.java line 456:
> 454: throw new IncompatibleClassChangeError(msg);
> 455: } else {
> 456: 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);
-------------
PR: https://git.openjdk.java.net/jdk/pull/7766
More information about the core-libs-dev
mailing list