U
Ulrich Eckhardt
Lew said:By checking for it first, you can fail gracefully, under full control.
But it definitely is under control. Other than in e.g. C++, where certain
actions invoke "undefined behaviour", trying to dereference null in Java is
well-defined and also works reliably.
I can imagine a case where it seems to make sense to first check for null,
and that is writing to a file. If you first open and truncate the file and
then write the changed recordset, you shouldn't touch the file if the
recordset was null. However, this is just an illusion, because if you go
for data integrity you also need to consider a full disk during write, and
then it doesn't buy you anything to first check for null.
By ignoring the null parameter, you crash your program all the way to
stack trace.
Right, you get a stack trace or an IDE might fire up the debugger at that
place, but I wouldn't call that a problem, there is not much more
information you could reasonably ask for. Of course, there are cases where
you wouldn't want to terminate the whole program but only the current
transaction, but that has to be considered anyway so the null argument is
not different to any other error.
The point of this stuff is to help you *fix* what's wrong. What good does
it do you to know something's wrong if you don't know what, where or how?
An NPE with the according stacktrace doesn't help you? To me, that is
usually enough to figure out what went wrong and where.
I think you have a very precise plan what you're doing, but the really
unfortunate thing is that you are not telling us. The only thing you are
communicating here is that alternative plans don't fit your goals and that
they are therefore crap. How about actually answering what
handleNullSituation() would do? Try to give examples!
Uli