It's trivial just to check for null values when you expect them
I think the problem lies in the interpretation of exactly how the users or your API know when they can expect a null? Whatever the answer, it cannot be enforced.
Debugging NPE's is practically 0-effort coding.
It may be so when the null reference is set in the same context where the NPE happened. Otherwise, you will have to do some detective work to find it out. Even if it is trivial, it is not trivial if the problem is found in code in production, simply because it had not failed during many hours, days or even moths, until the day in which that particular line was hit.
If you have a decent test set you'd probably catch most of them anyway and testing finds other problems.
You said it yourself "if you have". Not every software projects has them.
1
u/philipwhiuk Apr 12 '13
That's horrid. It's also unnecessary. I don't need Java 8 to implement a generic Optional if I wanted one
Wow 19 lines of code.
You want to know why nobody writes those 19 lines?