Dead Code Detection for All NetBeans Java Projects

I've selected a whole bunch of projects in NetBeans IDE below, each of which are, on disk, represented by a folder. Some are Maven-based, some Ant based, some Java EE, some Java SE, including a modular NetBeans Platform application. When I right-click and choose "Detect Dead Code", the Dead Code Detector will pop up and show the paths to the folder represented by each selected project. If within those folders any Java class files (i.e., compiled Java source files) are found, they will be analyzed for dead code. In other words, build the project, or compile individual packages or files, otherwise you'll not get any dead code detection results.

Here you see the full paths to the selected projects automatically displayed since I had those projects selected when invoking the "Detect Dead Code" action above:

And here you see the results, after clicking the "Detect dead code" button above and then enlarging the dialog a bit, i.e., possible dead code is identified. Not definitely dead code, but possibly dead code, based on the analysis done by the detector, and impacted by any filters you define. The next step is for me to show the info above as hyperlinks in the Output window.

Alternatively, go to the Source menu and near the end you'll see "Dead Code Detector", so that you can access it and use it even when you don't have any projects open in the IDE. Or press Ctrl-D which will pop up the detector too.

Go here to get the latest version of the plugin, i.e., version 1.2, which has all the support described in this blog entry:

Install it into NetBeans IDE 7.3.1 or above (the screenshots above come from NetBeans IDE 7.4 Beta). 

Much more info on how the tool works and how it will improve your life:


When invoked from the project tree, the dialog that comes up isn't big enough to show the output area - I initially thought the plugin didn't do anything and posted a query on nbusers about it. Then I saw this blog and tried it from the "Source" menu. There it worked as above.

But to be useful on any bigger project, this plugin really needs the ability to go to the suspect source. When I tried it on our very old project with 4000+ source files, I had literally hundreds of possible hits. Manually going to the suspect source/line is too laborious (but better than nothing, I guess).

Posted by guest on January 28, 2014 at 09:28 AM PST #

Thanks for the feedback. Would you like to work on that feature yourself?

Posted by Geertjan on January 28, 2014 at 10:00 AM PST #

Can I use this plugin for JDK 1.8 in NetBeans 8.0.2?

Posted by guest on March 05, 2016 at 08:56 PM PST #

Post a Comment:
  • HTML Syntax: NOT allowed

Geertjan Wielenga (@geertjanw) is a Principal Product Manager in the Oracle Developer Tools group living & working in Amsterdam. He is a Java technology enthusiast, evangelist, trainer, speaker, and writer. He blogs here daily.

The focus of this blog is mostly on NetBeans (a development tool primarily for Java programmers), with an occasional reference to NetBeans, and sometimes diverging to topics relating to NetBeans. And then there are days when NetBeans is mentioned, just for a change.


« July 2016