This pattern is neither good or not good. You'd need to evaluate it in context.
The key question is why someObject
can have null
values, and whether it is meaningful ... or a bug.
On the one hand, null
might have a specific meaning (e.g. something like "the value is unspecified"), and the code might be dealing with that in a legitimate way.
On the other hand, null
might be a symptom of a bug (e.g. someone forgot to initialize something). In that case, the code is spreading the damage and / or making the source of the bug harder to find ... and therefore bad.
As a general observation, a lot of code / coders take the view that the best way to avoid unexpected NPEs is to liberally scatter stuff like this throughout the code-base as a preventative measure. In fact, this is exactly the wrong thing to do. The right approach is to let the NPE happen (or better still, force it to happen -- see @vacuum's Answer), figure out where the unexpected null
is coming from ... and remove the source. And (of course!) you need to test extensively so that the unexpected nulls get picked up before you go into production.
IMO, it is best practice to treat a null
as an error unless it has a well defined and documented meaning.