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?
Using the following step filters skips all unwanted steps for now :
*$$* // for CGLib proxies
*$LocalBeanProxy // for other EJB proxies
java.*
net.sf.*
sun.*
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.
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.
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.
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.
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.*
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With