FindBugs is a “must-use” tool for any serious Java programmer to detect real and potential critical bugs in our code.
There are two different ways to use FindBugs:
- while we are coding (inside the IDE) and
- as a step in the project quality checks phase (usually via a maven plugin).
NetBeans support both usages.First of all, we need to enable the plugin “FindBugs Integration” in “Tools –> Plugins”
FindBugs analysis configuration is available in Tools –> Options –> Editor –> Hints.
Select FindBugs in the “Language” drop-down menu.
In this window, there is a “Run FindBugs in Editor” check-box. If enabled, FindBugs will be executed on the .java file we are working on (just after the save).
Note: FindBugs works on .class files and not on source (.java files).
FindBugs can be executed on the complete project using the Source –> Inspect function:
The results of the FindBugs analysis on the complete project is reported in the “Inspector” window:
- Editor level analysis is done on a single file and with minimal FindBugs effort (to avoid to slow down the editor)
- Inspection analysis is done on all project class files with deeper FindBugs effort. In this case, it is acceptable to have a slower but more accurate analysis.
The two different analysis can bring to different violations detected.