Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check for dead java methods at runtime

Tags:

java

dead-code

I am trying to create an index of unused Java methods in the form of a json file.

There are a couple different ways in which the methods can be referenced. I have already checked for all the other ways and have a relatively small list of possibly unused java methods.

The final way in which a method can be used is in other java files. They would be called with a basic class.method(args,args2,etc...) syntax somewhere in the java source code.

My question is, is there an easy way to just check my list of possible unused methods to see if any of them are not used in the java code. It would be ideal if this could be done at runtime, but it would also work if I could create a file that I could then read in at runtime.

I have tried using pre-built software like UCDetector, but the source code is huge, and running UCDetector takes hours and often doesn't even finish. It also checks all methods to see if they are used which is a waste of time since I have narrowed it down to a small number of possible methods to check.

like image 715
pythonHelpRequired Avatar asked Jun 16 '26 01:06

pythonHelpRequired


1 Answers

You should use your IDE (eclipse, intelliJ), or some static code analysis tool such as findbugs, pmd, checkstyle.

It seems like you are trying to reinvent the wheel.

like image 143
Marcin Szymczak Avatar answered Jun 17 '26 14:06

Marcin Szymczak



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!