Mark Stephens

Mark Stephens has been working with Java and PDF since 1999 and has diversified into HTML5, SVG and JavaFX.

He also enjoys speaking at conferences and has been a Speaker at user groups, Business of Software, Seybold and JavaOne conferences. He has a very dry sense of humor and an MA in Medieval History for which he has not yet found a practical use.

How we are improving our code quality with NetBeans in 2018

1 min read

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.

inspect menu

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.

NetBeans hints

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.

inspect and transform

A nice feature of the output is that you can view issues found by module in Maven

modules

or type in Maven. The light bulb will either give a hint or offer to fix the issue if possible.

type

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.

If you’re a first-time reader, or simply want to be notified when we post new articles and updates, you can keep up to date by social media (Twitter, Facebook and Google+) or the Blog RSS.

Mark Stephens

Mark Stephens has been working with Java and PDF since 1999 and has diversified into HTML5, SVG and JavaFX.

He also enjoys speaking at conferences and has been a Speaker at user groups, Business of Software, Seybold and JavaOne conferences. He has a very dry sense of humor and an MA in Medieval History for which he has not yet found a practical use.

Leave a Reply

Your email address will not be published. Required fields are marked *