what to do for nulls

Site menu:

Topics

Recent Posts

Blog

 

October 2008
M T W T F S S
« Sep   Nov »
 12345
6789101112
13141516171819
20212223242526
2728293031  

Past Posts

Links:

Archive for October 17th, 2008

what to do for nulls

October 17th, 2008 by Jeanne Boyarsky

A logical follow up to null checking in the extreme and Never return Null Arrays, is what we should be doing when a null does get returned.
The problem
Consider the following method:

public void method() {
StringBuilder builder = UnreliableCode.createBuilder();
if ( builder != null ) {
builder.append("data");
}

This time, a null check is appropriate because we can’t guarantee createBuilder() works [...]