Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I detect dead code in an enterprise Java project (Java + JSP + Javascript)?

Does anyone know of a tool for detecting dead code in a Java EE project?

I've looked into lots of tools that do this well for pure Java projects, but nothing seems to really handle projects which include JSPs and Javascript files as well. For example, detecting that a Java method is in use because it's being called from a JSP, or detecting that some JSP file that previously was used as an AJAX request is no longer called from any Javascript.

Thanks.

like image 649
Phil Avatar asked Aug 10 '11 19:08

Phil


1 Answers

What about real-life sampling? Plug-in JaCoCo agent to your application, run it and use it for a while. If you have thorough functional tests, run them. If you have a team of testers, let them click on your application. JaCoCo will record all executed lines (it is used for code coverage) in the meantime.

If some lines were not executed during extensive period of time (remember you would have to touch every possible screen, call, path and branch in your application) you should examine whether they aren't actually dead (or maybe you simply forgot to run your application in this particular configuration).

Understandably this is very fragile, but I don't think you will find anything automatic.

like image 120
Tomasz Nurkiewicz Avatar answered Oct 06 '22 00:10

Tomasz Nurkiewicz