I have made once this
this blog entry, and now I have changed my opinion a bit: A method should never return null if this indicates an error state.
e.g. Here is some code that should throw an exception instead of returing null:
public SomeObject createSomeObject() {
try {
//... some code
return someObject
} catch (Exception ex) {
return null
}
}
This code is fine, because if nothing is found is a valid state and not an error:
public SomeObject find(...) {
if (nothingIsFound) {
return null;
} else {
...
}
}