Useful message about NullPointerException

Bernd Eckenfels ecki at
Mon Jan 26 19:20:11 UTC 2015

Am Wed, 21 Jan 2015 05:45:08 -0700 (MST)
schrieb pike <pike630 at>:

> 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.


More information about the core-libs-dev mailing list