Geertjan's Blog

  • August 6, 2013

Dead Code Detection for All NetBeans Java Projects

Geertjan Wielenga
Product Manager

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:


Join the discussion

Comments ( 3 )
  • guest Tuesday, January 28, 2014

    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).

  • Geertjan Tuesday, January 28, 2014

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

  • guest Sunday, March 6, 2016

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

Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.