Bug 362411 - DRY when finalizing annotation-based aspects compiled with javac
Summary: DRY when finalizing annotation-based aspects compiled with javac
Status: NEW
Alias: None
Product: AspectJ
Classification: Tools
Component: LTWeaving (show other bugs)
Version: 1.6.8   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: aspectj inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-10-29 22:02 EDT by Brett Randall CLA
Modified: 2011-10-30 19:07 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Brett Randall CLA 2011-10-29 22:02:25 EDT
This is based on this email thread [1] and also related to this doc TODO [2].

Starting with AspectJ 1.6.8, there is a change to the way annotation-based aspects (@Aspect) are located by the weaver - I believe that an exhaustive search was expensive, and from 1.6.8 un-finished aspects need to be explicitly exposed to the LTW weaver.  Failure to do so will result in runtime errors e.g. of the form:

java.lang.NoSuchMethodError: <aspect classname>.aspectOf()Lcom/package/MyAspect;

This method is currently added via the weaver, when it finalizes javac-compiled aspects.  I don't expect ajc-compiled aspects to have the same problem when used with LTW.

The expectation for >= 1.6.8 is that aspects compiled with javac must be explicitly exposed to the weaver (whether or not they are being advised themselves).  This may pose problems for occasional AspectJ/LTW developer-users, who might expect that their aspects should be declared in <aspects>, and advice targets would be exposed to <weaver>.

For example, given a javac-compiled, annotation-based aspect com.package.MyAspect and a target to advise in com.targetpackage.MyTarget, in 1.6.7 this aop.xml suffices:

<aspectj>
    <weaver options="-verbose -showWeaveInfo">
        <include within="com.targetpackage.*"/>
    </weaver>

    <aspects>
        <aspect name="com.package.MyAspect"/>
    </aspects>
</aspectj>

From 1.6.8 through to 1.6.11, the javac-compiled aspect must be explicitly exposed to the weaver:

<aspectj>
    <weaver options="-verbose -showWeaveInfo">
        <include within="com.targetpackage.*"/>
	<include within="com.package.MyAspect"/>
    </weaver>

    <aspects>
        <aspect name="com.package.MyAspect"/>
    </aspects>
</aspectj>

This violates DRY, in that the deployer has to declare the aspect to <aspects>, as well as insuring that the aspect itself is exposed to the weaver for finalization.  One possible improvement is to check LTW declared aspects and if not finalized to weave them so they are finalized.

Relevant for changes made in 1.6.8, also confirmed on 1.6.11.

[1] http://dev.eclipse.org/mhonarc/lists/aspectj-users/msg12579.html
[2] https://bugs.eclipse.org/bugs/show_bug.cgi?id=330269
Comment 1 Andrew Clement CLA 2011-10-30 19:07:00 EDT
> I believe that an exhaustive search was expensive, and from 1.6.8 
> un-finished aspects need to be explicitly exposed to the LTW weaver.

Yep

> One possible improvement is to check LTW declared aspects and if
> not finalized to weave them so they are finalized.

Could do that, yes.  Although they won't be used for weaving we ought to 'fix them up' to be at least basically valid.