当使用Eclipse与FindBugs时,您可以将错误标记为不是错误,并将其从错误列表中删除? [英] When using Eclipse with FindBugs can you mark a bug as not a bug and have it removed from the bug list?

查看:128
本文介绍了当使用Eclipse与FindBugs时,您可以将错误标记为不是错误,并将其从错误列表中删除?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

FindBugs在我的代码中发现了一个潜在的错误。但是它不是一个错误。



是否可以将此事件标记为不是错误,并将其从错误列表中删除?



我已经清楚地记录了为什么每种情况都不是一个错误。



例如。一个类实现了可比较的接口。它有compareTo方法。但是我没有覆盖equals方法。



FindBugs不喜欢JavaDocs状态,建议

 (x.compareTo(y)== 0)==(x.equals(y))

尽管在我的情况下,上述条件是并且永远是真的。

解决方案

而不是使用过滤器,您也可以使用 SuppressWarnings 注释。您必须使用findbugs包中的注释,这意味着您需要导入或使用其完全限定名称。这是因为除了 SuppressWarnings JDK它具有保留Class,这是需要的,因为findbugs对编译的字节码而不是源代码进行操作。



示例:

  @ edu.umd.cs.findbugs.annotations.SuppressWarnings(
value =EQ_COMPARETO_USE_OBJECT_EQUALS,
justification =因为我知道更好)

有一个角落你可能不应该使用注释:如果你的代码是库代码最终在一个jar中,可以被其他项目使用,你仍然在Java5上。这样做的原因是JDK中的错误,如果注释不在类路径中。


FindBugs has found a potential bug in my code. But it is not a bug.

Is it possible to mark this occurrence as 'not a bug' AND have it removed from the bug list?

I have documented quite clearly why for each case it is not a bug.

For example. A class implements the comparable interface. it has the compareTo method. I have however not overridden the equals method.

FindBugs does not like this as the JavaDocs state that it is recommended that

(x.compareTo(y)==0) == (x.equals(y))

Although in my case the above condition is and always will be true.

解决方案

Instead of using filters, you can also use the SuppressWarnings annotation. You must use the annotation out of the findbugs package, meaning you either need an import or use the fully qualified name of it. This is because other than the SuppressWarnings from the JDK it has retention "Class", which is needed because findbugs operates on the compiled bytecode instead of source code.

Example:

@edu.umd.cs.findbugs.annotations.SuppressWarnings(
    value="EQ_COMPARETO_USE_OBJECT_EQUALS", 
    justification="because I know better")

There's one corner case where you probably should not be using the annotation: If your code is library code that ends up in a jar, that could be used by other projects and you're still on Java5. The reason for this is a bug in the JDK which crashes javac if the annotation is not in the classpath.

这篇关于当使用Eclipse与FindBugs时,您可以将错误标记为不是错误,并将其从错误列表中删除?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆