有没有办法忽略一个FindBugs警告? [英] Is there a way to ignore a single FindBugs warning?

查看:1218
本文介绍了有没有办法忽略一个FindBugs警告?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用PMD时,如果要忽略特定警告,可以使用 // NOPMD 来忽略该行。

With PMD, if you want to ignore a specific warning, you can use // NOPMD to have that line be ignored.

FindBugs有类似内容吗?

Is there something similar for FindBugs?

推荐答案

FindBugs初始方法涉及XML配置文件又名过滤器。这实际上不如PMD解决方案方便,但FindBugs适用于字节码,而不是源代码,因此评论显然不是一种选择。示例:

The FindBugs initial approach involves XML configuration files aka filters. This is really less convenient than the PMD solution but FindBugs works on bytecode, not on source code, so comments are obviously not an option. Example:

<Match>
   <Class name="com.mycompany.Foo" />
   <Method name="bar" />
   <Bug pattern="DLS_DEAD_STORE_OF_CLASS_LITERAL" />
</Match>

然而,为了解决这个问题,FindBugs后来推出了另一种基于注释(参见 SuppressFBWarnings )(比XML更方便)在我看来)。示例(也许不是最好的一个,但是,它只是一个例子):

However, to solve this issue, FindBugs later introduced another solution based on annotations (see SuppressFBWarnings) that you can use at the class or at the method level (more convenient than XML in my opinion). Example (maybe not the best one but, well, it's just an example):

@edu.umd.cs.findbugs.annotations.SuppressFBWarnings(
    value="HE_EQUALS_USE_HASHCODE", 
    justification="I know what I'm doing")

请注意,因为已弃用FindBugs 3.0.0 SuppressWarnings 而支持 @SuppressFBWarnings 因为名称与Java的 SuppressWarnings 发生冲突。

Note that since FindBugs 3.0.0 SuppressWarnings has been deprecated in favor of @SuppressFBWarnings because of the name clash with Java's SuppressWarnings.

这篇关于有没有办法忽略一个FindBugs警告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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