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

David Holmes dholmes at openjdk.java.net
Thu Mar 10 04:50:37 UTC 2022


On Wed, 9 Mar 2022 22:52:41 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.

Hi Mandy,

This is an enhancement request not a bug and I don't think adding a performance penalty to all correct code just to produce a slightly clearer NPE message for broken code, is the right trade-off here. 

Cheers,
David

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

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


More information about the core-libs-dev mailing list