76.

What We've Learned

In this chapter on the Split Cleaner bug pattern we've learned the following:

  • With Split Cleaners, the clean up code for a resource is split along the various possible execution paths.

  • Most Split Cleaners are also examples of Rogue Tiles because the clean up code along each path is likely to be identical.

  • One way to guarantee that you obtain and free a resource exactly once is to obtain and free it in the same method.

  • Another (bad) way is to trace through each possible execution path of the code to ensure that the resource is eventually freed in each instance. This will cause maintenance nightmares when a programmer unfamiliar with your code adds another execution path in which the resource is not freed.

  • When you find an execution path that doesn't include the appropriate clean up code, you might be tempted to simply add it to that path. That would be a bad fix.

  • Each method should be responsible for cleaning up resources that it acquires.

  • Extending code can make Split Cleaners appear more rapidly.

  • It is often a waste of time to try to anticipate and code for all the ways in which a program will be extended.

In Chapter 17 we'll look at instances of the Fictitious Implementation, a bug pattern that involves interface implementations that violate unchecked invariants.



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