If I get a NullPointerException in a call like this:
someObject.getSomething().getSomethingElse().
getAnotherThing().getYetAnotherObject().getValue();
The answer depends on how you view (the contract of) your getters. If they may return null
you should really check the return value each time. If the getter should not return null
, the getter should contain a check and throw an exception (IllegalStateException
?) instead of returning null
, that you promised never to return. The stacktrace will point you to the exact getter. You could even put the unexpected state your getter found in the exception message.