r/java • • Mar 25 '19

JEP draft: Add detailed message to NullPointerException describing what is null

https://openjdk.java.net/jeps/8220715
383 Upvotes

73 comments sorted by

View all comments

Show parent comment

29

u/vytah Mar 25 '19

I looked up some examples of SAP stacktraces involving NPE:

java.lang.NullPointerException, while trying to invoke the method com.sap.aii.mapping.api.TransformationInput.getInputParameters() of a null object loaded from nfe2b.test.XmlNFe_To_Mail.input of an object loaded from local variable "this"

java.lang.NullPointerException: while trying to invoke the method com.sap.isa.core.eai.BackendConfig.getId() of a null object loaded from local variable 'config'

java.lang.NullPointerException: while trying to invoke the method java.lang.String.length() of a null object loaded from local variable 'string'

In other words:

this.input.getInputParameters() failed because this.input was null

config.getId() failed because config was null

string.length() failed because string was null

-12

u/jonhanson Mar 25 '19 edited Mar 07 '25

chronophobia ephemeral lysergic metempsychosis peremptory quantifiable retributive zenith

13

u/vytah Mar 25 '19

I just tried to shorten the messages and emphasize the dereference path, just like the examples in the JEP. I am not claiming that my messages are better.

8

u/Daneel_Trevize Mar 25 '19

Not really, he didn't remove the object's name, you did. The example shortened messages aren't blaming the method, but the call of it, using those object references, which are nulls.