Skip to content

False positive about the rule NP_EQUALS_SHOULD_HANDLE_NULL_ARGUMENT #2558

@LynnBroe

Description

@LynnBroe

Version: 4.7.3

I found a false positive about the rule NP_EQUALS_SHOULD_HANDLE_NULL_ARGUMENT.

In the example below, SpotBugs reports no warning. The equals method takes a parameter that is marked as @javax.annotation.Nonnull . So it obeys this rule correctly.

public class Test {
    public boolean equals(@javax.annotation.Nonnull Object a) {
        return a.hashCode() == this.hashCode();
    }
}

However, in the example below, SpotBugs reports a warning at line 3 if we use @org.netbeans.api.annotations.common.NonNull instead. Actually, @javax.annotation.Nonnull and @org.netbeans.api.annotations.common.NonNull are equivalent. So, this exmaple does not violate the rule NP_EQUALS_SHOULD_HANDLE_NULL_ARGUMENT and the warning is a false positive.

public class Test {
    public boolean equals(@org.netbeans.api.annotations.common.NonNull Object a) { //report a warning, but it is an FP
        return a.hashCode() == this.hashCode();
    }
}

I use the cmd spotbugs -textui -low -xml -output= report.xml -auxclasspath org.eclipse.jdt.annotation-2.2.700.jar Test.class

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions