Why doesn't a null pointer exception provide an expression that is null?

If there is no line of code, for example, throw new NullPointerException();null pointers usually occur when an expression is executed that turns out to be null. So my question is: why does the message for a null pointer not contain an expression returning null?

+5
source share
2 answers

I do not know for sure, but I believe that the reason is that serious performance problems could arise if the JVM were to report the exact expression that caused the exception.

, , () ... , .

, ... ' .

+4

NullPointerException , null, . , , JVM , null, , -.


, :

String tmp = myObj.getSomething();
String result = tmp.substring(1);

1- NullPointerException ( , , , myObj.getSomething()), , myObj null. 2- NullPointerException, , tmp null, .. myObj.getSomething() null. , myObj.getSomething() null , if (tmp != null) { ... } else { ... } .

+4

All Articles