With PMD, if you want to ignore a specific warning, you can use // NOPMD
to have that line be ignored.
Is there something similar for FindBugs?
With PMD, if you want to ignore a specific warning, you can use // NOPMD
to have that line be ignored.
Is there something similar for FindBugs?
Here is a more complete example of an XML filter (the example above by itself will not work since it just shows a snippet and is missing the
<FindBugsFilter>
begin and end tags):If you are using the Android Studio FindBugs plugin, browse to your XML filter file using File->Other Settings->Default Settings->Other Settings->FindBugs-IDEA->Filter->Exclude filter files->Add.
Update Gradle
Locate the FindBugs Report
Find the specific message
Import the correct version of the annotation
Add the annotation directly above the offending code
See here for more info: findbugs Spring Annotation
As others Mentioned, you can use the
@SuppressFBWarnings
Annotation. If you don't want or can't add another Dependency to your code, you can add the Annotation to your Code yourself, Findbugs dosn't care in which Package the Annotation is.Source: https://sourceforge.net/p/findbugs/feature-requests/298/#5e88
At the time of writing this (May 2018), FindBugs seems to have been replaced by SpotBugs. Using the
SuppressFBWarnings
annotation requires your code to be compiled with Java 8 or later and introduces a compile time dependency onspotbugs-annotations.jar
.Using a filter file to filter SpotBugs rules has no such issues. The documentation is here.
The FindBugs initial approach involves XML configuration files aka filters. This is really less convenient than the PMD solution but FindBugs works on bytecode, not on source code, so comments are obviously not an option. Example:
However, to solve this issue, FindBugs later introduced another solution based on annotations (see
SuppressFBWarnings
) that you can use at the class or at the method level (more convenient than XML in my opinion). Example (maybe not the best one but, well, it's just an example):Note that since FindBugs 3.0.0
SuppressWarnings
has been deprecated in favor of@SuppressFBWarnings
because of the name clash with Java'sSuppressWarnings
.I'm going to leave this one here: https://stackoverflow.com/a/14509697/1356953
Please note that this works with
java.lang.SuppressWarnings
so no need to use a separate annotation.