by barrkel · 13y ago · 0 comments
Handily enough, C#, Java and similar languages actually throw an exception when you try to work with a null reference as if it wasn't null. These exceptions are generally only cryptic when the null references are stored somewhere other than the stack before being manipulated. That is, so long as foo(null) throws an exception before foo() returns, it's no big deal to diagnose, and mostly unnecessary to check the value of the parameter as it passes through the graph of method calls.
(To a degree I'm arguing a devil's advocate position, as I have a lot of sympathy for encoding not-null-by-default into the type system.)
This isn't something easily fixed by a compiler or language feature. There's no magic bullet.
Bugs "lying in wait" are a minor problem; if they lie in wait long enough, they are almost by definition not a problem at all.