Null pointer dereferencing refers to treating a null
variable as if it were a valid object or field and proceeding to use it without checking its state. Typically, this condition results in a NullPointerException
which may lead to sometimes result in denial of service. While other runtime exceptions can produce similar effects, NullPointerException
is often found to be the most frequent show-stopper.
...
Code Block | ||
---|---|---|
| ||
if (obj == null) { for(Iterator it = col.iterator();it.hasNext();) { // col is currently named coll if (it.next() == null) { count++; } } } else { for (Iterator it = col.iterator();it.hasNext();) { // col is currently named coll if (obj.equals(it.next())) { count++; } } } |
Wiki Markup |
---|
DereferencesNull ofpointer nulldereferences pointers can happen in many path dependent ways. Due to the limitations of automatic detection tools, code review and manual inspection of code are inevitableindispensable activities \[[Hovemeyer 07|AA. Java References#Hovemeyer 07]\]. Annotations for method parameters that must be non-null can also alleviate the occurrencesproblem to a certain extent by aiding automatic detection. |
...