[英]How to use @SuppressFBWarnings correctly to ignore printStackTrace findbugs warning
[英]What to import to use @SuppressFBWarnings?
要導入什么來使用SuppressFBWarnings? 我通過help / install新軟件安裝了findbugs插件當我輸入import edu。時,我無法通過ctrl空間來獲取選項。
例
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) {
...
}
有錯誤“edu無法解析為某種類型”
要使用FindBugs注釋,您需要在類路徑中包含FindBugs發行版中的annotations.jar和jsr305.jar 。 如果您確定只需要@SuppressFBWarnings
注釋(而不是其他 注釋 ),那么單獨使用annotations.jar即可 。
您可以在FindBugs發行版的lib文件夾中找到兩個JAR。
如果您使用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>
如果您使用的是Gradle:
dependencies {
compileOnly 'com.google.code.findbugs:annotations:3.0.1'
compileOnly 'com.google.code.findbugs:jsr305:3.0.1'
}
compileOnly
是Maven調用provided
范圍的Gradle風格。
SpotBugs更新(2018年):
FindBugs已被SpotBugs取代。 因此,如果您已經在使用SpotBugs, 遷移指南建議您使用以下依賴項:
請依賴於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>
搖籃:
dependencies {
compileOnly 'net.jcip:jcip-annotations:1.0'
compileOnly 'com.github.spotbugs:spotbugs-annotations:3.1.3'
}
如果您還使用了jsr305
,那依賴性仍然與上面相同。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.