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;








4 Responses to "FindBugs In Eclipse Tutorial"
  1. JGuru 2011-09-21 20:55:57.0
  1. admin 2011-09-22 16:55:27.0
  1. dongjun 2011-09-23 14:55:58.0
  1. padma naresh 2011-09-24 20:35:37.0

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