We're having trouble tracking down Null Pointer Exceptions in our code using Eclipse and I was wondering if Eclipse offered any help in this area. What ways does Eclipse offer to easily track down Null Pointer Exceptions?
To illustrate, here is a typical code example that is throwing an NPE:
if (myObject.getDimensionMap().get(keyValue.getConcept()).isMeasureDimension()) {
Unless I'm mistaken there are 5 possibilities where an object could be null:
- myObject could be null
- myObject.getDimensionMap could be null
- keyValue could be null
- keyValue.getConcept could be null
- myObject.getDimensionMap().get(keyValue.getConcept) could be null
Avoiding the argument of changing the code so each statement is on a different line, does Eclipse offer any way of helping to find the NPE without having to step into each statement? Bear in mind that it took the dev team quite a while to even get to this statement let alone find out which one of the elements was null (it was the getDimensionMap().get ).
Update:
It took so long to find the actual cause of the NPE because the offending code was buried in a deep call hierarchy, where the outer layer has a catch for all exceptions. The reason for this is so that the exceptions can then be rendered in a more attractive format and displayed to the user. So the code is like
try {
doSomething
...
callSomething
callSomethingElse
...
offending if test which throws the NPE
...
} catch (Exception e) {
// Format exception and pass back to client
}
Of course, the user never want to see the phrase NullPointerException....
Thanks.