Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] bug with pertarget ?

This is due to implicit limiting of join points when using any of the per- associations. For pertarget() associations, the advice application (or the scope of aspect) is limited to where the join point’s target object matches the aspect’s associated object
(target object at call(test.new(..))).

What more, in your aspect the target object at the pointcut specified in pertarget() specification will be the caller object (which in your scenario will be null).

Change the aspect as follows:
public aspect taspect perthis(execution(test.new(..))) {
after() : execution(* *.*(..)) && !within(taspect) {
System.err.println("GOT HERE");
}
}

-Ramnivas

===
Ramnivas Laddad,
Author, AspectJ in Action
http://ramnivas.com

David Pearce wrote:

Hi all,

I have encountered something strange and i'm wondering if its a bug or simply my misunderstanding. The test case is:

> public aspect taspect pertarget(call(test.new(..))) {
> after() : call(* *.*(..)) && !within(taspect) {
> System.err.println("GOT HERE");
> } }
>
> public class test {
> int aField;
> void aMethod() { aField = 0; }
>
> public static void main(String argv[]) {
> System.err.println("BEFORE");
> test t = new test();
> t.aMethod();
> System.err.println("AFTER");
> } }

Observed Output:

> BEFORE
> AFTER

But, I expected to see "GOT HERE" as well. What is more, if a change the first line to:

> public aspect taspect pertarget(initialization(test.new(..))) {

Then I do see "GOT HERE". But, I don't understand why the first one does not work ??

Cheers,

Dave
_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
http://dev.eclipse.org/mailman/listinfo/aspectj-users



Back to the top