Suppressing Trivial FindBugs Warnings for Android Projects

FindBugs is an extremely useful static analysis tool for Java code that will flag many subtle bugs and point out bad practice. However, when using FindBugs with Android projects, it will complain about the name of the auto-generated Android resource inner classes, which start with a lower-case letter, e.g. com.example.app.R$attr. Obviously, there is not much you can do to change the names, so these warnings are of little use.

By defining a filter for FindBugs, the warnings can be suppressed. Create an XML-file with the following content and include the file as a filter when running FindBugs.

<FindBugsFilter>
 <Match>
  <Class name="~.*\.R\$.*"/>
  <Bug pattern="NM_CLASS_NAMING_CONVENTION"/>
 </Match>
</FindBugsFilter>

If you run FindBugs through the Eclipse plugin, open Eclipse Preferences, go to Java > FindBugs and select the “Filter Files” tab. Click “Add…” next to “Exclude filter files” and select the XML-file you created earlier.

If you run FindBugs from a command line, include the option “-exclude <file.xml>”, where “<file.xml>” is the path and name of the XML-file you created.

The FindBugs filter mechanism is very versatile. Have a look at chapter 8 of the FindBugs manual for more information.

 

  • Print
  • email
  • Digg
  • StumbleUpon
  • del.icio.us
  • Facebook
  • Twitter
  • Google Bookmarks
  • Google Buzz
  • Posterous
This entry was posted in Android and tagged , . Bookmark the permalink.

4 Responses to Suppressing Trivial FindBugs Warnings for Android Projects

  1. Felipe Conde says:

    Very useful. Thanks

  2. Excellent! Thanks for saving me the time to tweak my filter to suppress those trivial warnings. Works like a charm.

  3. Pingback: Making Your Android App Better With Static Analysis | ProjectJourneyman on Android Income

  4. Snicolas says:

    Thx for this short but useful tip.

Leave a Reply

Your email address will not be published. Required fields are marked *