java 要导入什么才能使用@SuppressFBWarnings?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39412365/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What to import to use @SuppressFBWarnings?
提问by
What to import to use SuppressFBWarnings? I installed the findbugs plugin via help / install new software When I type import edu., I can't do ctrl space to get the options.
要导入什么才能使用 SuppressFBWarnings?我通过帮助安装了 findbugs 插件/安装新软件当我输入 import edu. 时,我无法按 ctrl 空间来获取选项。
Example
例子
try {
String t = null;
@edu.umd.cs.findbugs.annotations.SuppressFBWarnings(
value="NP_ALWAYS_NULL",
justification="I know what I'm doing")
int sl = t.length();
System.out.printf( "Length is %d", sl );
} catch (Throwable e) {
...
}
Has error "edu cannot be resolved to a type"
出现错误“edu 无法解析为类型”
回答by barfuin
In order to use the FindBugs annotations, you need to include annotations.jarand jsr305.jarfrom the FindBugs distribution on your classpath. If you are sure that you want the @SuppressFBWarnings
annotation only (and not the others), then annotations.jaralone would be sufficient.
为了使用 FindBugs 注释,您需要在类路径中包含来自 FindBugs 发行版的annotations.jar和jsr305.jar。如果您确定@SuppressFBWarnings
只需要注释(而不是其他注释),那么仅annotations.jar就足够了。
You can find the two JARs in the libfolder of the FindBugs distribution.
您可以在FindBugs 发行版的lib文件夹中找到这两个 JAR 。
If you are using Maven:
如果您使用的是 Maven:
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>annotations</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
If you are using Gradle:
如果您使用的是 Gradle:
dependencies {
compileOnly 'com.google.code.findbugs:annotations:3.0.1'
compileOnly 'com.google.code.findbugs:jsr305:3.0.1'
}
compileOnly
is the Gradle flavor of what Maven calls provided
scope.
compileOnly
是 Maven 称为provided
范围的 Gradle 风格。
Update for SpotBugs (2018):
SpotBugs 更新(2018 年):
FindBugs has been superseded by SpotBugs. So if you are already using SpotBugs, the migration guidesuggests that you use the following dependencies instead:
FindBugs 已被SpotBugs取代。因此,如果您已经在使用 SpotBugs,迁移指南建议您改用以下依赖项:
Please depend on both of spotbugs-annotationsand net.jcip:jcip-annotations:1.0instead.
请同时使用spotbugs-annotations和net.jcip:jcip-annotations:1.0。
Maven:
马文:
<dependency>
<groupId>net.jcip</groupId>
<artifactId>jcip-annotations</artifactId>
<version>1.0</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-annotations</artifactId>
<version>3.1.3</version>
<optional>true</optional>
</dependency>
Gradle:
摇篮:
dependencies {
compileOnly 'net.jcip:jcip-annotations:1.0'
compileOnly 'com.github.spotbugs:spotbugs-annotations:3.1.3'
}
If you also used jsr305
, that dependency remains the same as above.
如果您还使用了jsr305
,则该依赖项与上述相同。