One of our New Year’s resolutions for 2018 at IDRsolutions was to give the code base a thorough review and tidy. It has been written over the last 15 years and there are lots of areas which can be improved in 2018 (using newer Java constructs, rewriting with hindsight, repaying technical debt, removing used code, etc). I also like to think that I am a better coder in 2018 than I was in 2003….
As the main author (culprit?) for much of this code, I have been working on this task. There are lots of tools to help me with this, and I have been using a mixture of FindBugs, PMD and the static analysis tools in IDEA and NetBeans. I find these tools very complementary (they find different things). In this article, I will look at what NetBeans offers.
NetBeans IDE offers support for PMD and includes FindBugs as a core feature. It also has its own powerful static analysis tools. These can be run ‘interactively’, offering you hints as you look through the code or as a command.
The source menu includes an Inspect option which gives you access to the tools.
This allows you to set the scope (from single file to everything) and choose which Inspections to run as well as run a single Inspection. I usually choose All Analyzers.
If you use this option, NetBeans uses the default set in Preferences. It includes not just the NetBeans static analysis but FindBugs and other languages. There are comments for each and configuration options where appropriate.
The items in italics are issues which NetBeans can find, the ones not in italics are ones where NetBeans can not only find an issue but also suggest fixes. These can also be accessed from the Inspect and Transform menu option. You can create your own additional sets of Inspections and there are some predefined sets to Migrate your code base to a later Java release.
A nice feature of the output is that you can view issues found by module in Maven
or type in Maven. The light bulb will either give a hint or offer to fix the issue if possible.
I find the static analysis in NetBeans to be very fast in use compared to other tools.
If you have not discovered this powerful tool inside NetBeans IDE, it can really transform your code (and your reputation for writing high quality code – just keep it as our secret). As with any static analysis, start with an empty set and gradually turn on the Inspections which matter to you.
Next time I will look at static Analysis in IDEA.
Latest posts by Mark Stephens (see all)
- How we are improving our code quality with IDEA in 2018 - March 7, 2018
- How we are improving our code quality with NetBeans in 2018 - March 1, 2018
- 3 ways that the European Union is changing the way Companies write software in 2018 - January 31, 2018
- IDRsolutions product range update for 2018 - January 22, 2018
- 4 ways Companies can make remote working successful - December 21, 2017