This section describes the configuration and usage of the FindBugs plugin.
FindBugs works with three types of errors. You can visit http://findbugs.sourceforge.net/bugDescriptions.html for the FindBugs error details. The following are the FindBugs-supported error categories and errors:
tostring()
but it should be toString()
equal(Object)
but it should be equals(Object)
Serializable
, but doesn't define serialVersionUID
Serializable
serializable
inner classif (x < 0) new IllegalArgumentException("x must be nonnegative");
null
, for example, consider the following code:Object x = null; Car myCar = (Car)x; if(myCar != null){ //... }
The following is the update site URL for the FindBugs Eclipse plugin: http://findbugs.cs.umd.edu/eclipse.
You can also install it through Eclipse Marketplace.
Install FindBugs and then add the following code to the CodeQualityChapter06
project for verification:
public class Buggy implements Cloneable { private Integer magicNumber; public Buggy(Integer magicNumber) { this.magicNumber = magicNumber; } public boolean isBuggy(String x) { return "Buggy" == x; } public boolean equals(Object o) { if (o instanceof Buggy) { return ((Buggy) o).magicNumber == magicNumber; } if (o instanceof Integer) { return magicNumber == ((Integer) o); } return false; } Buggy() { } static class MoreBuggy extends Buggy { static MoreBuggy singleton = new MoreBuggy(); } static MoreBuggy foo = MoreBuggy.singleton; }
Right-click on the project and click on the Find Bugs menu. The following is the pop-up menu displayed:
Open the source file; it shows the bug icons. The following screenshot displays the bugs:
The following screenshot displays the bugs in a tabular format with the error categories: