...
Omitting the null check means that the program fails more quickly than if the program had returned false and lets an invoking method discover the null value. A method that throws a NullPointerException
without a null check must provide a precondition that the argument being passed to it is not null.
Noncompliant Code Example (
...
Null
...
Object Pattern)
Wiki Markup |
---|
This noncompliant code example is derived from the logging service null object design pattern described by Henney \[[Henney 2003|AA. References#Henney 03]\]. The logging service is composed of two classes: one that prints the triggering activity's details to a disk file using the {{FileLog}} class and another that prints to the console using the {{ConsoleLog}} class. An interface, {{Log}}, defines a {{write()}} method that is implemented by the respective log classes. Method selection occurs polymorphically at runtime. The logging infrastructure is subsequently used by a {{Service}} class. |
...