[英]Findbugs Java Ignore Fields or Lines
是否可以为特定字段或行创建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);
}
这行不通:
@edu.umd.cs.findbugs.annotations.SuppressFBWarnings(value="BEAN_SUPER_CALL_ON_OBJECT")
return super.equals(obj);
同样,这将不起作用:
@edu.umd.cs.findbugs.annotations.SuppressFBWarnings(value="BEAN_SUPER_CALL_ON_OBJECT")
super.equals(obj);
这可行,但是警告仍然弹出:
@edu.umd.cs.findbugs.annotations.SuppressFBWarnings(value="BEAN_SUPER_CALL_ON_OBJECT")
boolean ret_val = super.equals(obj);
return ret_val;
对于字段,这是可能的,但对于单行代码则不能。 根据FindBugs 3.0文档 ,可以将@SuppressFBWarnings
注释应用于
[目标]类型,字段,方法,参数,构造函数,包
(在edu.umd.cs.findbugs.annotations
包中, @SuppressFBWarnings
和@SuppressWarnings
是等效的。)
如您所见, LOCAL_VARIABLE
和ANNOTATION_TYPE
不在列表中。 尽管注释上没有@Target
元素,但是在这两种情况下,FindBugs会忽略它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.