82.

What We've Learned

In this chapter on the Dangling Composite bug pattern, we've learned the following:

  • A Dangling Composite results from defining a recursive data type so that certain base cases of the definition are not assigned their own classes.

  • Null pointers in place of classes create the "dangling" references.

  • A Dangling Composite confuses null pointers with placeholders for base cases.

  • Representing lists directly as null pointers is not a solution since it would be impossible to remove the last list element; it is also impossible to insert an element into an empty list. In addition, under these circumstances a .equals call on an empty list would signal a NullPointerException.

  • The easiest cure is also a prevention: give each base case of the data type its own class.

  • Again, creating unit tests for the code can help eliminate the introduction of bugs into the program.

We aren't finished with null pointer dereferences just yet. In Chapter 10, we'll take a look at yet another common bug pattern that manifests itself as a NullPointerException. You'll learn how to recognize this pattern and how to avoid it.



Bug Patterns in Java
Bug Patterns In Java
ISBN: 1590590619
EAN: 2147483647
Year: N/A
Pages: 95
Authors: Eric Allen

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net