Detecting Null Pointer Violations in Java Programs

The use of formal methods has been growing steadily and there have been a number of successful
applications of formal methods in a range of application areas. It seems agreed that quality should
be assured by applying testing, analysis and formal methods to rigorously dened precode artifacts.
The detection of null pointer violation errors is definitely such a goal. This way of applying formal
methods has a great potential to increase our confidence in the software. The goal is to provide a
practical mechanism to assist the application of formal methods in the early detection of null pointer
violation errors in programs and the solution is theorem proving based and is focused on the
identification of the possible places in which a theorem prover could assist in the detection of null
pointer violation errors and the formulation of the necessary proof obligations.

The theorem prover partially assists in checking the conditions used to control the logical flow of a
program by evaluating the proof obligations formed from the path under examination. A research prototype
is under development and the preliminary results are encouraging and demonstrate the feasibility and
effectiveness of our approach.

public class MyClass1 {
protected String s1, s2;
// constructor 1 public void method2 () {
public MyClass1(…) { String s3;
s1 = new String(…); if (cond1) {
} s3 = new String(…);
// constructor2 //…
public MyClass1(…) { if (cond2) {
s1 = new String(…); …s3.length…
s2 = new String(…); }
public void method1() {
… s2.length() …
A null pointer example-1

Null Pointer Detection is fundamental to the problem of program analysis. Some of the problems related
to detecting null pointer errors are aliasing, name collision, unexecutable paths, uninitialized
pointers, Any tool involving automatic program analysis is likely to benefit from information about null
pointers in a program. Null pointer information is essential to knowing the state of the pointer at an
arbitrary point in a program for conducting other analyses (array index out of bounds) class cast exception
Consider the example in example-1.

In MyClass1 two instance variables, s1 and s2, are declared. However the programmer forgets to initialize s2
in constructor 1, which is a very common mistake – forgetfulness. The consequence is that the dereferencing
of s2 in method1 may cause a null pointer exception at runtime. In method2, the local variable s3 is
initialized inside an if statement, and is dereferenced inside a different if statement. The dereference
may also cause a null pointer exception at runtime if cond2 is not implied by cond1. These types of errors
are very common in programs.


, , , , , , , ,

  1. #1 by Sandy on August 7, 2012 - 7:48 pm

    That was well discussed and detailed info of detecting null pointer in java programs. It seems I’m reading a book with lots of information content page by page.:D

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: