FindBugs™ is a program to find bugs in Java programs. It looks for instances of "bug patterns" --- code instances that are likely to be errors.

Using FindBugs

FindBugs can be run as a standalone application. The FindBugs manual covers this type of operation in the manual.

You can have it analyze the classes directly or point it to a findbugs result file. The latter comes in handy when you combine it with maven. In CloudStack we can enable a profile for maven that will generate findbugs output in the target directory.

 

For example if you want to find bugs in core

$ mvn -P enablefindbugs -pl :cloud-core verify

This will generate a file called findbugs.xml in the target directory. You can load this file into the ui.

FindBugs and IntelliJ

The Intellij findbugs plugin can be downloaded @ http://plugins.jetbrains.com/plugin/3847

Once its installed, you can right click on the file -> FindBugs -> Analyze current fileThis will show the results in the find bugs console with a nice explanation for each error.

FindBugs and Eclipse

The Eclipse plugin for FindBugs is called "FindBugs Feature" and is available from the Eclipse update sites or the Eclipse market place.

Once it is installed you can right click on a project and select "Find Bugs" from the FindBugs menu. When the FindBugs check has run you can switch to the FindBugs perspective and browse through the findings.

More information

FindBugs webpage : http://findbugs.sourceforge.net

More static code analysis

  • No labels