Showing posts with label nullpointerexception. Show all posts
Showing posts with label nullpointerexception. Show all posts

Wednesday, May 23, 2012

How to avoid "!= null' statements in Java?


I work with Java all day long. The most used idiom (code snippet) I'm programming in Java, is to test if an object != null before I use it, to avoid a NullPointerException of course. But the code looks very ugly and becomes unreadable.

Thursday, March 8, 2012

Is Catching a Null Pointer Exception a Code Smell?


Recently a co-worker of mine wrote in some code to catch a null pointer exception around an entire method, and return a single result. I pointed out how there could've been any number of reasons for the null pointer, so we changed it to a defensive check for the one result.