Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Step into Java EE code in Eclipse

Debugging sessions in Eclipse and Java EE code are a pain and I'm hoping someone has a better method than mine.

Here is a typical call stack between 2 EJB stateless bean methods (using TomEE 1.0) :

NativeMethodAccessorImpl.invoke0(Method, Object, Object[]) line: not available [native method]  
NativeMethodAccessorImpl.invoke(Object, Object[]) line: 39  
DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: 25  
Method.invoke(Object, Object...) line: 597  
ReflectionInvocationContext$BeanInvocation(ReflectionInvocationContext$Invocation).invoke() line: 181   
ReflectionInvocationContext.proceed() line: 163 
StatsInterceptor.record(InvocationContext, Method) line: 176    
StatsInterceptor.invoke(InvocationContext) line: 95 
GeneratedMethodAccessor35.invoke(Object, Object[]) line: not available  
DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: 25  
Method.invoke(Object, Object...) line: 597  
ReflectionInvocationContext$InterceptorInvocation(ReflectionInvocationContext$Invocation).invoke() line: 181    
ReflectionInvocationContext.proceed() line: 163 
CdiInterceptor.invoke(InvocationContext) line: 129  
CdiInterceptor.access$000(CdiInterceptor, InvocationContext) line: 45   
CdiInterceptor$1.call() line: 66    
CdiInterceptor.aroundInvoke(InvocationContext) line: 72 
GeneratedMethodAccessor34.invoke(Object, Object[]) line: not available  
DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: 25  
Method.invoke(Object, Object...) line: 597  
ReflectionInvocationContext$InterceptorInvocation(ReflectionInvocationContext$Invocation).invoke() line: 181    
ReflectionInvocationContext.proceed() line: 163 
InterceptorStack.invoke(Object...) line: 138    
StatelessContainer._invoke(Method, Method, Object[], Instance, ThreadContext, InterfaceType) line: 226  
StatelessContainer.invoke(Object, InterfaceType, Class, Method, Object[], Object) line: 178 
StatelessEjbObjectHandler(EjbObjectProxyHandler).synchronizedBusinessMethod(Class<?>, Method, Object[], Object) line: 260   
StatelessEjbObjectHandler(EjbObjectProxyHandler).businessMethod(Class<?>, Method, Object[], Object) line: 240   
StatelessEjbObjectHandler(EjbObjectProxyHandler)._invoke(Object, Class, Method, Object[]) line: 91  
StatelessEjbObjectHandler(BaseEjbProxyHandler).invoke(Object, Method, Object[]) line: 284   
MyService$LocalBeanProxy.removeScheduledEvent(ScheduledEvent) line: not available   

That's 30 lines of Java EE plumbing method calls that I don't want to inspect!

My only reliable way to skip all this when stepping into a method is to put a breakpoint in the next method call, then hit "Step Over" instead of "Step Into". However, setting breakpoints all the time like that is a major hassle compared to a simple "Step Into". I have to repeat the same thing when I need to step out of the method I'm inspecting.

I know about step filters in Eclipse and tried using those but some automatically-generated proxy classes are injected in my own packages so I can't easily use that.

Does anybody have a good solution for this?

update

Using the following step filters skips all unwanted steps for now :

*$$*  // for CGLib proxies
*$LocalBeanProxy  // for other EJB proxies
java.*
net.sf.*
sun.*

edit 2

Here's an example from the MyService class:

public void removeScheduledEvent(ScheduledEvent event) {
    // ...
    otherEJB.doStuff(event);
}

Since otherEJB is an EJB bean running in a stateless container, the 30 calls above are inserted automatically via proxies.

like image 495
bernie Avatar asked Oct 26 '12 16:10

bernie


People also ask

How do I step through Java in Eclipse?

Simply put, you can run your code in Debug Mode by pressing only F11 or clicking that little bug on the top of the screen. Use F5 to trace into, F6 to step over, CTRL-SHIFT-B to set/remove breakpoints.

How do I run a debug code in Eclipse?

A Java program can be debugged simply by right clicking on the Java editor class file from Package explorer. Select Debug As → Java Application or use the shortcut Alt + Shift + D, J instead. Either actions mentioned above creates a new Debug Launch Configuration and uses it to start the Java application.

Can we write Java code in Eclipse?

Step 1: To create a new Java project in Eclipse, go to File > New > Project. Step 2: The New Java Project wizard dialog appears to let you specify configurations for the project. Select the Java Project option in it. Step 3: After that, you will see the below screen.


2 Answers

Some info about Eclipse step filters:

Eclipse debugging / step into method skipping AOP wiring

How to filter dynamically generated classes in debug view?

Actual step filters I use with TomEE:

*$LocalBeanProxy
*$CGLibInterceptor
net.sf.*
org.apache.geronimo.*
org.apache.naming.*
org.apache.openejb.*
org.apache.tomee.*
org.apache.webbeans.*
like image 119
bernie Avatar answered Oct 05 '22 22:10

bernie


When debugging, simply hold CtrlAlt, hover over the method name where you want to stop again, until it turns into a hyperlink, then click the method name. That feature is called Step into Selection.

like image 44
Bananeweizen Avatar answered Oct 05 '22 23:10

Bananeweizen