I'm wondering if it is an accepted practice or not to avoid multiple calls on the same line with respect to possible NPEs, and if so in what circumstances. For example:
anObj.doThatWith(myObj.getThis());
vs
Object o = myObj.getThis();
anObj.doThatWith(o);
The latter is more verbose, but if there is an NPE, you immediately know what is null
. However, it also requires creating a name for the variable and more import statements.
So my questions around this are:
- Is this problem something worth designing around? Is it better to go for the first or second possibility?
- Is the creation of a variable name something that would have an effect performance-wise?
- Is there a proposal to change the exception
message to be able to determine what
object is
null
in future versions of Java ?