beatrice
beatrice

Reputation: 4431

How to find unused code in a huge codebase

It's a java springboot application with intellij.

The problem is:

  1. intellij makes mistakes when it comes to finding unused code (marking unused as used or vica versa)
  2. The codebase contains huge amount of custom hacks*

*by custom hack I mean that class instantiation seems completely random like:
-using @Autowired
-using getBean
-using @Autowired on a collection of interface implementations and just refering the instance by the index (lol)

@Autowired
List<MyInterface> myList
public doSomething(){
myList.get(0).calculate()
}

-using reflection:

val classToInstantiate = "<some_prefix>"+getMiddlePartWithSomeStupidLogic()+"<parameter_as_suffix>"
Class<?> cls = Class.forName(classToInstantiate);
cls.getConstructors()[0].newInstance(params..)

I feel that every package or class is written by different developer.

I feel completely impossible to explore the dead code in an easy way. So I started to do it by hand - like searching every field/class/method name by hand - but it would take weeks and it is still errorprone.

So is there an easy and fast way for this?

Upvotes: 0

Views: 88

Answers (0)

Related Questions