kedar mhaswade wrote > On Mon, Jan 26, 2015 at 11:20 AM, Bernd Eckenfels <
> ecki@ > > > wrote: > >> Am Wed, 21 Jan 2015 05:45:08 -0700 (MST) >> schrieb pike < > pike630@ > >: >> >> > 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 <https://en.wikipedia.org/wiki/Law_of_Demeter>? > 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 >> Hmm, based on the JVM specification, there is Descriptor structure which can be used to describe the name and type of a field or method in a class. I think, the JVM can use this info to display the type of the object which is null when NPE is thrown. Furthermore, I think the constant pool also includes all the information about the fields in a class. They can be used as well. -- View this message in context: http://openjdk.5641.n7.nabble.com/Useful-message-about-NullPointerException-tp213240p213845.html Sent from the OpenJDK Core Libraries mailing list archive at Nabble.com.