简体   繁体   中英

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;

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM