Community
Participate
Working Groups
From the mailing list: Hi Andy, Thank you so much! Unfortunately we have a little ltw vs. source weaving problem. Consider I have the following setup: Source Weaving: ############## package ch.annotation; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.FIELD) public @interface Anno { } package ch.aspects; import ch.annotation.Anno; public aspect TriggerAll { declare @field : * *.myInt : @Anno; before(Anno anno) : @annotation(anno) && set(* *.myInt) { System.out.println("Triggered"); } } package ch.tests; public class MyObject { public int myInt; public int getMyInt() { return myInt; } public void setMyInt(int myInt) { this.myInt = myInt; } } package ch.tests; public class Main { public static void main(String[] args) { MyObject mo = new MyObject(); mo.myInt = 13; mo.setMyInt(13); } } This outputs: Triggered Triggered // two times "Triggered". As expected. Now LTW: ######## Infos: - -javaagent:lib/aspectjweaver.jar is set - the compiled aspect "TriggerAll.aj" is in the class searchpath (classpath) packed within a jar file. public class MyObject2 { public int myInt; public int getMyInt() { return myInt; } public void setMyInt(int myInt) { this.myInt = myInt; } } public class Main { public static void main(String[] args) { MyObject2 mo = new MyObject2(); mo.myInt = 13; mo.setMyInt(13); } } This outputs: Triggered // just one "Triggered" message. And this comes from mo.setMyInt(13). So mo.myInt = 13 does not trigger the pointcut! Note: It has nothing to do with your recent changes. This happens on AspectJ 1.6.12. Output form the weaving "process": [AppClassLoader@5acac268] info AspectJ Weaver Version 1.6.12 built on Tuesday Oct 18, 2011 at 17:52:06 GMT [AppClassLoader@5acac268] info register classloader sun.misc.Launcher$AppClassLoader@5acac268 [AppClassLoader@5acac268] info using configuration /path/META-INF/aop.xml [AppClassLoader@5acac268] info using configuration /other-path/lib/TriggerAll.jar!/META-INF/aop-ajc.xml [AppClassLoader@5acac268] info register aspect ch.aspects.TriggerAll [AppClassLoader@5acac268] info weaver operating in reweavable mode. Need to verify any required types exist. [AppClassLoader@5acac268] debug weaving 'Main' [AppClassLoader@5acac268] debug weaving 'MyObject2' [AppClassLoader@5acac268] weaveinfo 'public int myInt' of type 'MyObject2' (MyObject2.java) is annotated with @Anno field annotation from 'ch.aspects.TriggerAll' (TriggerAll.aj:6) [AppClassLoader@5acac268] weaveinfo Join point 'field-set(int MyObject2.myInt)' in Type 'MyObject2' (MyObject2.java:11) advised by before advice from 'ch.aspects.TriggerAll' (TriggerAll.aj:8) [AppClassLoader@5acac268] debug weaving 'ch.aspects.TriggerAll' [AppClassLoader@5acac268] info processing reweavable type ch.aspects.TriggerAll: ch\aspects\TriggerAll.aj [AppClassLoader@5acac268] debug cannot weave 'org.aspectj.lang.NoAspectBoundException' [AppClassLoader@5acac268] debug weaving 'ch.annotation.Anno' [AppClassLoader@5acac268] debug weaving '$Proxy3' Triggered But again: Thanks very much for you effort
This problem also occurs in straight compilation if the files are passed in in a particular order. For example: === ajc Anno.java TriggerAll.java MyObject.java Main.java -1.5 -d . -showWeaveInfo 'public int myInt' of type 'ch.tests.MyObject' (MyObject.java) is annotated with @Anno field annotation from 'ch.aspects.TriggerAll' (TriggerAll.java:6) Join point 'field-set(int ch.tests.MyObject.myInt)' in Type 'ch.tests.MyObject' (MyObject.java:11) advised by before advice from 'ch.aspects.TriggerAll' (TriggerAll.java:8) Join point 'field-set(int ch.tests.MyObject.myInt)' in Type 'ch.tests.Main' (Main.java:7) advised by before advice from 'ch.aspects.TriggerAll' (TriggerAll.java:8) === ajc Anno.java Main.java TriggerAll.java MyObject.java -1.5 -d . -showWeaveInfo 'public int myInt' of type 'ch.tests.MyObject' (MyObject.java) is annotated with @Anno field annotation from 'ch.aspects.TriggerAll' (TriggerAll.java:6) Join point 'field-set(int ch.tests.MyObject.myInt)' in Type 'ch.tests.MyObject' (MyObject.java:11) advised by before advice from 'ch.aspects.TriggerAll' (TriggerAll.java:8) === Notice in the second case there is only one advised field-set. In the compilation case this is because at the time the match is attempted for @annotation() against the field-set joinpoint the type containing the field hasn't gone through the compiler and into the weaver. Therefore it hasn't been affected by the declare @field yet. When it works it is because the type is through into the weaver before the @annotation match is attempted.
I imagine the LTW scenario is also ordering, so now I'll convert what i have into LTW tests.
There are two bugs related to this specific issue: bug 133770 and bug 286473. These relate to the same problem which is matching against something that hasn't been through the weaver yet. Under 133770 the following option was added '-Xset:completeBinaryTypes=true' which can be set in weaver options. As discussed in 133770 it may misbehave when in a non-straightforward classloader configuration and so was turned OFF by default. Turning it ON doesn't fix the issue here though. That is because complete binary types wasn't enhanced to support declare @field/@method it was only built to handle declare parents and declare @type. Extending it to support declare @field makes the testcode pass just fine.
> Extending it to support declare @field makes the testcode pass just fine. Nice findings Andy. Thanks. Would be great to see another dev build.
dev build is on the download page now - try it out. Remember to use -Xset:completeBinaryTypes=true in the weaver options section of your aop.xml