tumblr counter

FindBugs In Eclipse Tutorial

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

Note

If you interested on PMD Eclipse Plugin (another source code analysis tool), You can follow PMD Eclipse Tutorial

If you interested on Eclipse Checkstyle Tutorial (another code analysis tool), You can follow Eclipse Checkstyle Tutorial

If you interested on Sonar Eclipse Plugin (another source code analysis tool), You can follow Eclipse Sonar Tutorial

Findbugs Tutorial

You need to download

  1. Eclipse 3.7
  2. FindBugs 1.3.9

You can install the FindBugs Eclipse plugin using Eclipse update manager from the following links

  1. http://findbugs.cs.umd.edu/eclipse ( It is for official releases)
  2. http://findbugs.cs.umd.edu/eclipse-candidate  ( It is for  official releases and candidate releases)
  3. 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

FindBugs Installation

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

FindBugs Configuration

Using FindBugs Plugin

Finding bugs using FindBugs, you need to create a java project and add the following class into src

public class FindBugsTest {
 
public static void main(String args[]){
   
System.out.println(new Integer(10));
 
}
}

Running FindBugs

Note

FindBugs is analyzing the byte code, so you need to build the project before running FindBugs.

Now, Build the project using Project->Build Project. Right click on the project, and run the FindBugs according to following screenshot.

Running FindBugs

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 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 is immutable, so invoking a method on a immutable object, will not update the object

String str = "Javatips.net       ";
str.trim
();
//Static field can be accessed and changed by malicious code or by an accident, so it should be declared as final

public static byte FIND_FLAG = 0;



Findbugs Tutorial Findbugs Eclipse Plugin FindBugs Install FindBugs Configuration Findbugs Source Code Analysis How To Configure Findbugs Plugin With Eclipse PMD Vs FindBugs FindBugs Static Code Analysis FindBugs Code Review Tool FindBugs Code Coverage Tool FindBugs Source Code Analysis FindBugs Code Inspection

You might also like following tutorials :

Java Tutorial Apache CXF Tutorial Hibernate Tutorial Spring Tutorial Struts Tutorial
4 Comments on "FindBugs In Eclipse Tutorial"
21.05.2013 11:03:06 JGuru
Nice article, very helpful, thanks
23.05.2013 10:27:09 admin
@JGuru,
I am very glad that you liked findbugs tutorial, Thanks
25.06.2013 05:14:06 dongjun
thanks :)
28.02.2014 03:35:05 padma naresh
thank you very much..