Friday, May 9, 2014

Null pointer deference in find bugs

I have faced null pointer deference, when I checked the code standard with tool. It shows NULL pointer deference in severity 1.

Normally it will come when you are not handling null values. For example,

if ( URL != null) {System.out.println( "URL is NOT NULL + URL );}

ok fine. You are checking URL is not null. But in case , URL come as null, what will happen? Null pointer Exception error will thrown.

So this error called Null Pointer Dereference error. ok, How to handle this. See below for solution.

if ( URL != null) {System.out.println( "URL is NOT NULL + URL );}
        else {
        System.out.println( "URL is NULL " );
         throw new IllegalArgumentException();
}

Thats all.

No comments:

Post a Comment