Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (10.2k points)

What tools do you use to find unused/dead code in large java projects? Our product has been in development for some years, and it is getting very hard to manually detect code that is no longer in use. We do however try to delete as much unused code as possible.

Suggestions for general strategies/techniques (other than specific tools) are also appreciated.

 Note that we already use code coverage tools (Clover, IntelliJ), but these are of little help. The dead code still has unit tests and shows up as covered. I guess an ideal tool would identify clusters of code which have very little other code depending on it, allowing for docues manual inspection.

1 Answer

0 votes
by (46k points)
I would instrument the running system to keep records of code usage, and then start examining code that is not practiced for months or years.

For instance, if you are involved in unused classes, all classes could be instrumented to log when instances are created. And then a tiny script could match these logs against the entire list of classes to find unused classes.

Of course, if you go to the course level you should keep your performance in memory. For example, the methods could only log their first use. I don't know how this is completely made in Java. We have done this in Smalltalk, which is a powerful language and thus allows for code modification at runtime. We instrument all systems with a logging call and uninstall the logging code after an order has been logged for the first time, thus after any time no more performance penalties happen. Maybe a similar situation can be done in Java with static boolean flags...

Related questions

0 votes
1 answer
asked Nov 24, 2019 in Java by Anvi (10.2k points)
0 votes
1 answer
0 votes
1 answer
asked Oct 26, 2019 in Java by Anvi (10.2k points)
0 votes
1 answer

Browse Categories

...