25.

This chapter is a quick interlude to expose you to null pointers and the NullPointerException, a frequently occurring cause of several bug patterns.

One of the most common (and most commonly complained about) symptoms of bugs in Java programming is a thrown NullPointerException. Tracking down the cause of such exceptions can truly make you question your career decision. They provide no useful information as to why they were thrown and they are difficult-perhaps impossible in many cases-to predict.

They're Uninformative

Of all the exceptions a Java programmer might encounter, the NullPointerException is among the most dreaded, and for good reason: it is one of the least informative exceptions that a program can signal.

Unlike, for example, a ClassCastException, a NullPointerException says nothing about what was expected instead of the null pointer. Furthermore, it says nothing about where in the code the null pointer was actually assigned.

In many NullPointerExceptions, the true bug occurs where the variable is actually assigned the null value. To find the bug, we have to trace back through the flow of control to discover where the variable was assigned and determine whether doing so was incorrect. This process can be particularly frustrating when the assignment occurs in a package other than the one in which the error was signaled.



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