Useful message about NullPointerException

kedar mhaswade kedar.mhaswade at
Mon Jan 26 20:16:44 UTC 2015

On Mon, Jan 26, 2015 at 11:20 AM, Bernd Eckenfels <ecki at>

> 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
> happens.
​Maybe the objects in question are not talking only to their immediate
friends <>?
This happens when we tend to do something like *a.getB().getC()* and we
can't tell by looking at the NPE stack trace (which works on lines of
source code) if *a* was null or what *a.getB()* returned was null.

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.

> Gruss
> Bernd

More information about the core-libs-dev mailing list