Re: NullPointerException, IllegalArgumentException, or AssertionError
for null constructor argument
Lew wrote:
I agree with your conclusion, but quibble over a detail. Assertions do not
"exist to make low-severity bugs into high-severity ones" at all.
Mark Rafn wrote:
I was being glib, but there is some truth behind my statement. The reason to
have assertions in code (as opposed to just comments, or non-assertion
conditions that throw exceptions, is to ensure that a mismatch between the
developer's expectations and reality causes an event that's very hard to
miss.
Specifically, expectations and reality in the domain of algorithmic invariants
and like issues. Contrast to exceptions, that expose such a mismatch in the
domain of data correctness or environmental conditions.
It might be clearer to say that assertions turn logic bugs into crash bugs.
Contrast to exceptions, that turn data or environment bugs into recoverable bugs.
That crash bugs are higher severity than more subtle misbehavior is not universal.
I'm not sure that seeing "DangerDangerException ... [stack trace]" on a user's
screen is subtle misbehavior. Maybe compared to having a klaxon go off in
conjunction?
Assertions turn crash bugs into logged, analyzable crash bugs, and they do it
before you go into production.
If I translate "severity" into "visibility" I agree with your characterization
of assertions. I was using a different definition of "severity".
The quibble has vanished in the bright light of agreement.
--
Lew