Further to my question below, here's another example where something really seriously
screwy is happening. The basic infrastructure comes from the
docs/aspect-framework/examples/annotation example, but some of the files are modified and
there is one new file:
Driver.java
=======
public class Driver {
public static void main(String[] args) {
SUBPOJO spojo = new SUBPOJO(2);
spojo.someMethod();
}
}
POJO.java
=======
public class POJO {
@trace int field;
public POJO() {
}
public POJO(int i) {
field = i;
}
@billable public void someMethod() {
System.out.println("someMethod");
System.out.println("FIELD = " + field);
}
}
SUBPOJO.java
=========
public class SUBPOJO extends POJO {
private int field;
public SUBPOJO() {
}
public SUBPOJO(int i) {
super(i/2);
field = i;
}
public void someMethod() {
System.out.println("ENTERING SUBPOJO:someMethod");
super.someMethod();
System.out.println("LEAVING SUBPOJO:someMethod");
}
}
Here is the jboss-aop.xml file:
<?xml version="1.0" encoding="UTF-8"?>
| <aop>
| <bind pointcut="execution(POJO->@billable(..))">
| <interceptor class="BillingInterceptor"/>
| </bind>
| <bind pointcut="execution(* POJO->@billable(..))">
| <interceptor class="BillingInterceptor"/>
| </bind>
| <bind pointcut="all(@trace)">
| <interceptor class="TraceInterceptor"/>
| </bind>
| </aop>
If I remove the "@trace" from the definition of field "field" in
POJO.java then this works almost as expected:
run:
[java] ENTERING SUBPOJO:someMethod
[java] billing...[advisedMethod=public void POJO.someMethod(), unadvisedMethod=public
void POJO.POJO$someMethod$aop(), metadata=null, targetObject=SUBPOJO@a4e743,
arguments=null]
[java] someMethod
[java] FIELD = 1
[java] LEAVING SUBPOJO:someMethod
FIELD is correctly displayed as 1 (the value of POJO.field). I say "almost"
because I don't expect "billable" to be applied but suspect there's some
means of making that happen.
However if I put back the "@trace" in the definition of "field" in
POJO.java then this is what happens:
run:
[java] <<< Trace : write field name: int POJO.field
[java] >>> Leaving Trace
[java] <<< Trace : write field name: int POJO.field
[java] >>> Leaving Trace
[java] ENTERING SUBPOJO:someMethod
[java] billing...[advisedMethod=public void POJO.someMethod(), unadvisedMethod=public
void POJO.POJO$someMethod$aop(), metadata=null, targetObject=SUBPOJO@1112783,
arguments=null]
[java] someMethod
[java] <<< Trace : read field name: int POJO.field
[java] >>> Leaving Trace
[java] FIELD = 2
[java] LEAVING SUBPOJO:someMethod
Now the value read for field is WRONG. It is reading SUBPOJO.field rather than POJO.field.
This appears to be because of the way that jboss aop rewrites the accessor method,
switching from static to dynamic binding.
Even more oddly, if I change jboss-aop.xml to look like this:
<?xml version="1.0" encoding="UTF-8"?>
| <aop>
| <bind pointcut="call(POJO->@billable(..))">
| <interceptor class="BillingInterceptor"/>
| </bind>
| <bind pointcut="call(* POJO->@billable(..))">
| <interceptor class="BillingInterceptor"/>
| </bind>
| <bind pointcut="all(@trace)">
| <interceptor class="TraceInterceptor"/>
| </bind>
| </aop>
Then this is what happens:
run:
[java] <<< Trace : write field name: int POJO.field
[java] >>> Leaving Trace
[java] <<< Trace : write field name: int POJO.field
[java] >>> Leaving Trace
[java] ENTERING SUBPOJO:someMethod
[java] billing...SUBPOJO_1_MByMInvocation@1989f84
[java] ENTERING SUBPOJO:someMethod
[java] billing...SUBPOJO_1_MByMInvocation@110c424
[java] ENTERING SUBPOJO:someMethod
[java] billing...SUBPOJO_1_MByMInvocation@1bd2664
[java] ENTERING SUBPOJO:someMethod
[java] billing...SUBPOJO_1_MByMInvocation@1238bd2
[java] ENTERING SUBPOJO:someMethod
[java] billing...SUBPOJO_1_MByMInvocation@b0bad7
etc etc....
Ad infinitum, or at least until there is a stack overflow. This also appears to be down to
a code rewrite that replaces static binding with dynamic binding.
Is there some configuration mechanism to avoid these errors - which are about as
fundamental as I can imagine - or do I switch to aspectj which seems to get this right?
View the original post :
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3968029#...
Reply to the post :
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&a...