AspectJ around advice prevents coverage

62 views
Skip to first unread message

bjk...@gmail.com

unread,
May 19, 2017, 2:38:13 PM5/19/17
to JaCoCo and EclEmma Users
I have a project using build-time AspectJ to apply "around" advice to a method. The AspectJ compiler renames/mangles the original method name (e.g., from "method" to "method_aroundBody0"), changes it to static and passes the instance var as the first parameter, adds the Synthetic class attribute, and creates a new method with the original name that does before/after logic and ultimately delegates to the new "method_aroundBody0" method. Of course, the Synthetic class attribute means that JaCoCo ignores execution data for that method.

The behaviors of AspectJ and JaCoCo seem reasonable in isolation, but their interaction is unhelpful. What can we do about this situation? If the AspectJ compiler added metadata so JaCoCo could know that a method is renamed, would it be acceptable to read that metadata in the analyzer? Other thoughts?

bjk...@gmail.com

unread,
May 19, 2017, 2:39:50 PM5/19/17
to JaCoCo and EclEmma Users, bjk...@gmail.com
I forgot to mention, I created a simple Gradle project to demonstrate the bad interaction in case anyone wants to try themselves: https://github.com/bjkail/sample-jacoco-aspectj

Marc R. Hoffmann

unread,
May 22, 2017, 1:09:58 PM5/22/17
to jac...@googlegroups.com
Hi,

a workaround might be to use JaCoCo offline instrumentation before
ApectJ is applied.

In general JaCoCo is fully based on Java class files. Due to this design
choice the JaCoCo agent sees class exactly the way how they get
executed. With offline instrumentation in some situation JaCoCo
instrumentation can be applied before other tools modify the class files.

Regards,
-marc

Brett Kail

unread,
May 23, 2017, 8:32:36 AM5/23/17
to JaCoCo and EclEmma Users
Yes, that would work as a workaround.

Thoughts on longer-term solutions that would be acceptable between JaCoCo and AspectJ?  Perhaps AspectJ could add a "SyntheticMethodName" method attribute to the class file to indicate the method was renamed but the method body is still present in the .class file, and then JaCoCo could read the attribute and still process the method data?  Other thoughts?
Reply all
Reply to author
Forward
This conversation is locked
You cannot reply and perform actions on locked conversations.
0 new messages