I usually take code analysis tools with a grain of salt, and with an extra shot of espresso if it’s early, but one tool that has proven useful many times is FindBugs, which is available as an Eclipse plugin. It’s easy to install because it has an update site – so there’s no excuse, go grab it. To run, right-click your Java project and select the “Find Bugs” option. There are a few options for viewing the results: they appear as markers
in open editors, there are specialized views (Window > Show Views > Other… > FindBugs – start with Bug Tree View, the other views open automatically as you use this one) or you can see the results in the standard Problems view.
The FindBugs plugin is helpful when you are doing code reviews and, if you don’t tell anyone you’re using it, they’ll think you’re so clever for finding that “Load of known null value” or “May expose internal representation by incorporating reference to mutable object”… don’t worry, the names aren’t so confusing when you look at the code.
Today’s tip:
FindBugs plugin: a program which uses static analysis to look for bugs in Java code