Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What to import to use @SuppressFBWarnings?

People also ask

What is Suppressfbwarnings?

@SuppressWarnings instruct the compiler to ignore or suppress, specified compiler warning in annotated element and all program elements inside that element. For example, if a class is annotated to suppress a particular warning, then a warning generated in a method inside that class will also be separated.

How do you stop Spotbug errors?

To suppress violations you can use filter file. In this case you need to override default filter file. Spotbugs can't use default @SuppressWarnings annotation because it's a source annotation and not available in bytecode.


In order to use the FindBugs annotations, you need to include annotations.jar and jsr305.jar from the FindBugs distribution on your classpath. If you are sure that you want the @SuppressFBWarnings annotation only (and not the others), then annotations.jar alone would be sufficient.

You can find the two JARs in the lib folder of the FindBugs distribution.

If you are using 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:

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.


Update for SpotBugs (2018):

FindBugs has been superseded by SpotBugs. So if you are already using SpotBugs, the migration guide suggests that you use the following dependencies instead:

Please depend on both of spotbugs-annotations and net.jcip:jcip-annotations:1.0 instead.

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.