簡體   English   中英

要使用@SuppressFBWarnings導入什么?

[英]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.jarjsr305.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-annotationsnet.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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM