Stefan Sprenger
Stefan Sprenger

Reputation: 1080

Findbugs Java Ignore Fields or Lines

Is it possible to make a Findbugs deactivation annotation for a specific field or line instead of deactivation of the whole check of all method contained fields?

@edu.umd.cs.findbugs.annotations.SuppressFBWarnings(value="BEAN_SUPER_CALL_ON_OBJECT",
justification = "I don't want to overwrite the method, but otherwise our equals check issues a warning")
@Override
public boolean equals(final Object obj) {

    // this should not be ignored
    super.test(obj);

    // this should be ignored
    return super.equals(obj);

}

This won't work:

@edu.umd.cs.findbugs.annotations.SuppressFBWarnings(value="BEAN_SUPER_CALL_ON_OBJECT")
return super.equals(obj);

Also this won't work:

@edu.umd.cs.findbugs.annotations.SuppressFBWarnings(value="BEAN_SUPER_CALL_ON_OBJECT")
super.equals(obj);

This works, but the warning still pops up:

@edu.umd.cs.findbugs.annotations.SuppressFBWarnings(value="BEAN_SUPER_CALL_ON_OBJECT")
boolean ret_val = super.equals(obj);
return ret_val;

Upvotes: 0

Views: 2037

Answers (1)

barfuin
barfuin

Reputation: 17474

It is possible for fields, but not for single lines of code. According to the FindBugs 3.0 documentation, the @SuppressFBWarnings annotation can be applied to

[Target] Type, Field, Method, Parameter, Constructor, Package

(In the edu.umd.cs.findbugs.annotations package, @SuppressFBWarnings and @SuppressWarnings are equivalent.)

As you can see, LOCAL_VARIABLE and ANNOTATION_TYPE are not in the list. Although there is no @Target element on the annotation, FindBugs ignores it in these two cases.

Upvotes: 2

Related Questions