Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FindBugs - Redundant Comparison to null

I am having findbugs error for the below code,

if( obj instanceof CustomerData )
{
    CustomerData customerData = (CustomerData)obj;

    if (customerData == null) 
    {
        errors.reject("Error", "Null data received");
    }
}

Error Desc:

Redundant nullcheck of obj, which is known to be non-null in (Package and Method name, I have removed due to security violation)

This method contains a redundant check of a known non-null value against the constant null.

Please let me know what is the error in here.

like image 702
Srinivasan Avatar asked Jul 13 '11 12:07

Srinivasan


1 Answers

instanceof returns false if the argument is null. So you don't need another check.

like image 69
paradigmatic Avatar answered Sep 22 '22 16:09

paradigmatic