Useful message about NullPointerException
pike630 at hotmail.com
Tue Jan 27 11:47:07 UTC 2015
Bernd Eckenfels-4 wrote
> Am Wed, 21 Jan 2015 05:45:08 -0700 (MST)
> schrieb pike <
>> We frequently see NullPointerException in our logs. It's really a big
>> headache when we see a NullPointerException and it is encapsulated in
>> another exception as we don't know which object is null and it is
>> throwing an Exception. Is there any way we can get to know the object
>> type or the object variable name where the object is null and it is
>> throwing a NullPointerException? i.e, instead of just saying there is
>> a NullPointerException, can we add some friendly message?
> Note that if you keep the stack information in an exception it points
> (most of the time) exactly to the location where the null access
> I can imagine it is rather hard for the VM to add more informations.
> Your best bet is to avoid the NPEs and log the exceptions properly.
This is acually not helpful in some situations. For example, as what kedar
has mentioned, if there is a call "a.getB().getC()" and a NPE is thrown.
There might be two situations:
1. a is null;
2. a.getB() is null
So it would be better if there can be one friendly message which indicates
what is null.
View this message in context: http://openjdk.5641.n7.nabble.com/Useful-message-about-NullPointerException-tp213240p213842.html
Sent from the OpenJDK Core Libraries mailing list archive at Nabble.com.
More information about the core-libs-dev