简体   繁体   English

Findbugs Java忽略字段或行

[英]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? 是否可以为特定字段或行创建Findbugs停用注释,而不是停用所有方法包含字段的整个检查?

@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 根据FindBugs 3.0文档 ,可以将@SuppressFBWarnings注释应用于

[Target] Type, Field, Method, Parameter, Constructor, Package [目标]类型,字段,方法,参数,构造函数,包

(In the edu.umd.cs.findbugs.annotations package, @SuppressFBWarnings and @SuppressWarnings are equivalent.) (在edu.umd.cs.findbugs.annotations包中, @SuppressFBWarnings@SuppressWarnings是等效的。)

As you can see, LOCAL_VARIABLE and ANNOTATION_TYPE are not in the list. 如您所见, LOCAL_VARIABLEANNOTATION_TYPE不在列表中。 Although there is no @Target element on the annotation, FindBugs ignores it in these two cases. 尽管注释上没有@Target元素,但是在这两种情况下,FindBugs会忽略它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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