逐步抑制findbugs警告

3
我想要通过在方法的开始之前输入以下行来抑制单个Findbug警告(“将非常量字符串传递给SQL语句上的执行方法”):
@edu.umd.cs.findbugs.annotations.SuppressWarnings(value = {"SQL_NONCONSTANT_STRING_PASSED_TO_EXECUTE", "SQL_PREPARED_STATEMENT_GENERATED_FROM_NONCONSTANT_STRING" }, justification = "just a test")

但是Eclipse一直提示说edu无法解析为类型,而且在SuppressWarnings注释类型中未定义属性justification。我在findbugs文档中读到,我必须在Java Build Path(在项目属性中)中添加annotations.jar和jsr305.jar。但是在findbugs文件夹中,我找不到任何.jar文件。只有findbugs.xml、findbugs-excludes.xml等文件。

我该如何使其正常运行?我使用的是Findbugs Maven插件2.5.2。

非常感谢!


如果您使用SuppressFBWarnings,则不必完全限定它。 - David Harkness
1个回答

3

下载该文件并将其添加至您的类路径:

http://www.java2s.com/Code/Jar/a/Downloadannotations201jar.htm

或者使用官方的Maven仓库:

<dependency>
    <groupId>findbugs</groupId>
    <artifactId>findbugs</artifactId>
    <version>1.0.0</version>
</dependency>

链接:http://mvnrepository.com/artifact/findbugs/findbugs/1.0.0 或者使用以下Maven片段:
<dependency>
    <groupId>com.kenai.nbpwr</groupId>
    <artifactId>edu-umd-cs-findbugs-annotations</artifactId>
    <version>unknown</version>
</dependency>

我尝试使用了Maven代码片段。我将其添加到findbugs-maven-plugin-2.5.2.pom中,但是edu仍无法解析为类型。 - Mario Arbert

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接