On 01/21/2015 01:45 PM, pike wrote: > 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?
The line number gives you the position in the source code, and from that, you can usually figure out the static type. If this is not helpful in your case, you need to say why (no debugging information? multiple candidates per line?). The dynamic type is a different matter though, because null has no specific type at run time. It may be possible to provide type information in theory, at a cost, but this would best be prototyped through byte code rewriting. Nullable annotations would also help to pin-point location of the first leak, and you could record that (including a stack trace) if you want something really fancy. Whether it is helpful for legacy code, I don't know. There should be some research projects out there covering this area. -- Florian Weimer / Red Hat Product Security