lördag 30 augusti 2008

FindBugs is cool

This week we started to use a new tool in our biggest project called FindBugs. I read about this tool in Java Power Tools.

What this tool does is to find code that has bugs or has some other errors that you should take care of. These are issues that you compiler wont tell you.
Some examples:

You need a instance of Long and you do like this:
Long l = new Long(1);

if (l != null && l.equals("null")){
....

Java compiler wont say anything but probably you will get in trouble when this code is executed because you executing equals againts a String instance.

Another example is that how you should create Number instances:
Long l = new Long(1);

Better way is using Long.valueOf(1) and this is what findbugs will tell you.
Or in some situationes using autoboxing.

These are only some examples and there a lot of more situations where FindBugs will help you.

We have a small project with about 10 classes and a couple of thousand lines of code. I used FindBugs on it and cleared all warnings and errors. There where about 100 of those before. Extremly cool to have something not generating the smallest warning.

This tool was extremly simple to install in Eclipse (http://findbugs.cs.umd.edu/eclipse/) and to make a task for it in Ant is 5 minute work.
Now im thinking what tool we could start using in the project next week.

Inga kommentarer: