I’m always looking for simple ways that I can improve my Java programming. And SpotBugs, CheckStyle and PMD can help me do that.
NOTE: updated 20200625 because I no longer use QAPlug or FindBugs, I install PMD, CheckStyle and SpotBugs directly from the IntelliJ plugins.
I’m always looking for simple ways that I can improve my Java programming.
I use PMD and SpotBugs and CheckStyle IntelliJ Plugins my IDE.
Using Static Analysis
Using Static Analysis is like having a coach sitting by you when you are writing code. And some of the suggestions the tools make you won’t understand, so you have to search and learn what they mean - forcing you to learn that little bit more about your chosen language.
Don’t take all the suggestions at face value. You choose which suggestions to act on, and you can configure the tools to warn you about some things and not others.
Over time, you might choose to add the command line and build versions of the tools into your CI process rather than just your personal coding approach.
- right click on the project
- choose “PMD”
- choose profile
- analyse the results
- configure using Preferences \ Tools \ Checkstyle
- set to scan scope including tests
- click the Checkstyle tab
- Check Project
- Analyse the results
- click the SpotBugs tab
- analyse project file including test sources
- Analyse the Results
Demo of QAPlug plugin with PMD, FindBugs and CheckStyle
QAPlug wraps it all up in an right click menu item to Analyze the source code and shows all the items in a list for you to work through.
Just make sure you double click on the lowest branch in the tree to jump right to the code position where the tool identified the issue or suggestion.