I have Eclipse setup with "The AspectJ Development Tools" plugin. I'm trying to debug some code that uses AspectJ and step through it, but it is unable to match up the source lines since AspectJ has added extra stuff at compile time. No one else seems to be complaining about what seems like a major flaw (being unable to debug!), so I'm hoping I just need to tweak something to make it work. What am I doing wrong?
Yes, this is a bug with AspectJ. Stepping through advice has the incorrect file attribute attached to it. The best workaround is to delegate to a proper method inside of your advice and the line numbers will be aligned.
So far I have encountered the behaviour you described only with @Around
advice. @Before
or @After
advices have never confused the debugger I use.
@Around
is by default inlined in weaved classes (includes target class and the aspect itself). This is different from other advices I have tried. Inlining makes it difficult if not impossible for debugger to follow the flow.
You can disable inlining in AspectJ compiler, which will produce weaved classes in debugger friendly way. Disabled inlining may produce slower code and more weaved classes (auxiliary classes are created).
The maven way:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
<configuration>
<source>${java.compiler.source}</source>
<target>${java.compiler.target}</target>
<complianceLevel>${java.compiler.target}</complianceLevel>
<!-- Avoid some optimizations that make debugger useless. -->
<XnoInline>true</XnoInline>
</configuration>
</plugin>
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