Getting call hierarchy in java

I'm having trouble finding an error, and it would be useful to know which method is called a particular method. Is there an easy way to get call hierarchy from java? Java is a small part of the application, so I cannot compile and run the entire application in eclipse / net beans, so I do not have access to the call hierarchy of the IDE debugger.

+6
java hierarchy call
source share
4 answers
Thread.currentThread().getStackTrace(); 

or

 Exception ex = new Exception(); ex.printStackTrace(); 

This is pretty slow but great for debugging. The docs API is here .

+14
source share

Java is a small part of the application, so I cannot compile and run the entire application in eclipse / net beans, so I do not have access to the call hierarchy of the IDE debugger.

You do not need to run the application at all. If you create a project in Eclipse, you can use its built-in call hierarchy tool to find all the possible places that call the method.

There is a trade-off: the call hierarchy tool will give you ALL the places where the method is called from. This is good if you want / should know all the possibilities. The Neslson Thread.currentThread().getStackTrace() will give you places where the method is called from during your program for this call. The caveat is that you cannot run every code path during this call. If you see specific behavior and want to know how you got there, use the getStackTrace() parameter.

+1
source share

Have you tried using the Java remote debugging feature? Google search to get you started if you don’t have

0
source share

It is best to throw an exception, catch it immediately and analyze the stack trace.

I believe Log4J is able to register the calling method.

0
source share

All Articles