2 ms·
The first paragraph begins with a whole bunch of flawed assumptions. "The basis of this discussion is the observation that NPE is quite common" Not in my code
by wlievens 17y ago
The first paragraph begins with a whole bunch of flawed assumptions.
"The basis of this discussion is the observation that NPE is quite common"
Not in my code. Use design by contract and NPE is no longer aproblem
"...most of the times it is "fixed" by writing code to check that offendingObject != null before whatever triggered the NPE."
Not in my code. When an object is null you figure out the appropriate response to that. Either it shouldn't be allowed to be null at this point, and you find out why that is and fix that, or it should be allowed and you react appropriately to it. What's the problem?
"a simple solution to NPE is to replace NPE with a default "behavior" for all/any methods that are invoked on null object references: do nothing."
Except that doing nothing is impossible. Inaction is an action too, look at your average contrived ethical conundrum for illustration.
How is NPE different from any other sort of bug? You find a problem? You fix it, preferably just after writing a failing test case for it.