is an open-source static analysis tool designed to find bugs in your Java code. Unlike many other static analysis tools, however, FindBugs concentrates almost exclusively on isolating potentially dangerous coding errors that could break your application. This powerful tool can find subtle yet dangerous bugs that other static analysis tools will not detect.
FindBugs works by searching compiled Java bytecode for what it calls "bug patterns." Simply put, a bug pattern is a coding practice that often leads to bugs. Bug patterns are based on the observation that people tend to reproduce the same errors, both individually and collectively. Humans are creatures of habit, and habits tend to persist—even harmful ones. Inexperienced developers often make the same mistakes that more experienced developers were making when they were newbies. So, unless a conscious effort is made to identify and correct a poor programming habit, it will raise its head again and again. In particular, trickier parts of the Java language APIs can lead to common mistakes.
FindBugs comes with over 300 bug patterns (336 in FindBugs 1.3.4), organized in different bug categories, such as "Malicious Code," "Bad Practice," and "Performance." Each bug also has a priority rating (high, medium, and low). You can use this rating system to prioritize your bug-correction activities. The FindBugs team recommends treating both high- and medium-priority issues seriously.
In addition to isolating the most dangerous of these poor coding habits and mistakes, FindBugs also explains in great detail what is wrong with the code. This feature makes FindBugs not only an effective bug detector but also an excellent learning tool: it can help hone a team's programming skills and help individual developers avoid similar mistakes in the future.
Coding standards are generally recognized as a good thing, and any tool that helps you enforce your organization's own coding conventions is certainly worthwhile. While many coding best practices focus on making your code more readable and easier to maintain, FindBugs has a very different focus: finding nasty bugs and subtle errors that will crash your application, often at the worst possible time.
This article briefly introduces FindBugs, showing in particular how to use it in Eclipse, and then demonstrates its features with a few examples.
|What You Need
|Lots of memory (at least 512MB are recommended)