javaspotbugs

Suppress Spotbugs warnings globally


I have one warning from spotbugs. This is suppressed with @SuppressFBWarnings in all those files. I need to find a way to suppress this from one place so that I don't have to @SuppressFBWarnings in each file in that package.


Solution

  • You can use a filter file

    <?xml version="1.0" encoding="UTF-8"?>
    <FindBugsFilter>
    <Match>
      <Class name="my.package.*" />
    </Match>
    </FindBugsFilter>
    
    

    This file can be given to spotbugs as command line argument -exclude, or if you are using an IDE it probably can be configured to be used somewhere.

    This is especially useful when you want to exclude third-party code, or generated code, where you can't add the annotation to begin with. But it also helps separate the spotbugs configuration and the code.

    Also note the name attribute can be a regular expression.