Wednesday, April 08, 2009

Filtering in FindBugs

Here is an example findbugs exclusion filter which is generally useful for most projects. I could not seem to find a good example of something general anywhere so hopefully this will be a helpful reference to others. If you placed an xml file like this into your project in eclipse you can configure findbugs to use it as an exclusion filter.

Here is the sample xml (escaped):
<!-- filter out test classes with medium (2) or low (3) warnings -->
<Class name="~.*\.AbstractTest.+" />
<Class name="~.*Test" />

<!-- remove the rules which require all passed vars to be immutable -->
<Bug code="EI,EI2" />

<!-- Filter out certain categories of bugs -->
<Bug category="STYLE" />

To make this work in eclipse (with findbugs plugin installed) just do the following:
  1. Create an xml file in your project with the contents from above
  2. Right click the project name and select Properties
  3. Choose FindBugs
  4. Check the box marked Run FindBugs automatically
  5. Click on the Filter files tab at the top
  6. Click the Add button next to Exclude filter files:
  7. Select the xml file you created
  8. Click OK
You can adjust the filter using the findbugs guide and the full list of bug types and categories is available.

No comments: