Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Added a reference to ERR08-J

...

When using this pattern, the NULL object must be a singleton and must be final. It may be either public or private, depending on the overall design of the DataElement class. The state of the NULL object should be immutable after creation; immutability can be enforced either by using final fields or by explicit code in the methods of the DataElement class. See [Grand 2002] Chapter 8, "Behavioral Patterns, the Null Object,"€ for additional information on this design pattern, and also ERR08-J. Do not catch NullPointerException or any of its ancestors.

Applicability

Leaving short-lived objects in long-lived container objects may consume memory that cannot be recovered by the garbage collector, thereby leading to memory exhaustion and possible denial of service attacks.

...