23.

They're Elusive

Many Java developers note that the vast majority of program crashes they encounter are NullPointerExceptions; they long for a tool that would statically identify these bugs before the program is run. Unfortunately, automata theory- the study of machines, robots, or systems which follow a preset sequence of instructions automatically-tells us that no tool could ever statically determine exactly which programs will throw NullPointerExceptions.

But it is possible for a tool to rule out NullPointerExceptions for many expressions in a program, leaving us with just a few small potential trouble spots that we must then examine manually. In fact, several research efforts are now underway to provide just such a tool for Java programs (see the Resources chapter). But a good tool can only take us so far.

Note 

Automata theory says that no tool can ever statically determine exactly which programs will throw NullPointerExceptions.

NullPointerExceptions will never be completely eradicated. When they do occur, it helps us to know the bug patterns associated with them so that we can diagnose them quickly. In addition, we can use certain programming and design techniques to significantly minimize the occurrence of these patterns.

Now, on to two bug patterns that list null pointers as their cause: the Dangling Composite and the Null Flag.



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