FindBugs In Eclipse Tutorial
FindBugs In Eclipse Tutorial explains step by step details of installing and configuring findbugs plugin with eclipse.
What is FindBugs?
How to configure findbugs plugin with eclipse?
FindBugs is a free static source code analysis tool created by David Hovemeyer and Bill Pugh which helps you to find the bugs in your java code and improve the code quality. FindBugs uses static analysis on java code to find the bugs.
FindBugs works on byte code rather than source code, So FindBugs should be run after building the project
FindBugs is available as a small GUI application. Also plug-ins available for Netbeans, IntelliJ IDEA & Eclipse.
Another options are FindBugs maven plugin and FindBugs ant plugin
Findbugs Tutorial
You need to download
You can install the FindBugs Eclipse plugin using Eclipse update manager from the following links
- http://findbugs.cs.umd.edu/eclipse ( It is for official releases)
- http://findbugs.cs.umd.edu/eclipse-candidate ( It is for official releases and candidate releases)
- http://findbugs.cs.umd.edu/eclipse-daily (It includes developmental releases and other release candidate)
FindBugs Installation
For Installing FindBugs Plugin from eclipse, select Help->Install New Software Then click add, then provide Name and Location according to the following screenshot
Then select the FindBugs version click next and accept the license details, it will install the FindBugs
FindBugs Configuration
After install, you can configure FindBugs from eclipse, Window->Preferences->Java->FindBugs
Here you can apply FindBugs filter, in order to utilizing different Findbugs bug patterns
Using FindBugs Plugin
Finding bugs using FindBugs, you need to create a java project and add the following class into src
public static void main(String args[]){
System.out.println(new Integer(10));
}
}
Running FindBugs
Now, Build the project using Project->Build Project. Right click on the project, and run the FindBugs according to following screenshot.
Now you can see a bug mark on the source code, double click the bug mark, Bug Explorer will be shown ( You can also navigate to Window->Show View->Other->FindBugs->Bug Explorer).
FindBugs Properties
From properties tab, You can get more detailed description about this bug(See the below screenshot).
You can enable properties tab by navigating to Window->Show View->Properties.
FindBugs Helps You To Avoid Bad Code
There is always have possibilities for bugs on agile written code.
Here are some examples in which FindBugs helps you to avoid bad or malicious code.
String str = "Javatips.net ";
str.trim();
public static byte FIND_FLAG = 0;