Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] call from advice body

Hi Doug -

Yes, you should be able to advise join points in advice.

This looks like a long-standing bug with calling a method 
from advice advising the same method-call join point.  
Other method-call join points in advice can be advised fine, 
and this case worked fine in AspectJ 1.0, so long as the
factBaseCase(..) around advice is first/precedent.  

It's worth submitting as a bug; I'll do that if I don't hear
from you that you've done so.  Thanks for finding it.

Wes

> ------------Original Message------------
> From: Doug Orleans <dougo@xxxxxxxxx>
> To: aspectj-users@xxxxxxxxxxx
> Date: Tue, Oct-5-2004 4:05 PM
> Subject: [aspectj-users] call from advice body
>
> I have the following aspect:
> 
> aspect Fact {
>   static int fact(int n) {
>     throw new RuntimeException("Message not understood: fact(" + n + 
> ")");
>   }
> 
>   pointcut factBaseCase(int n):
>     factCall(n) &&
>     if(n == 0);
>   int around(): factBaseCase(int) { return 1; }
> 
>   pointcut factCall(int n):
>     call(int fact(int)) &&
>     args(n);
>   int around(int n): factCall(n) { return n * fact(n-1); }
> 
>   public static void main(String[] args) {
>     System.out.println(fact(5));
>   }
> }
> 
> It throws the exception: Message not understood: fact(4)
> But if I change factCall to use execution instead of call, it works
> fine (printing 120).
> 
> Why doesn't the call to fact(4) get advised?  Is there some rule that
> advice can't apply to calls from advice bodies?
> 
> --dougo@xxxxxxxxx
> 
> P.S. It would be nice to rewrite factBaseCase as follows:
> 
>   pointcut factBaseCase():
>     factCall(int n) &&
>     if(n == 0);
> 
> since the pointcut doesn't actually need to expose any context.  Is
> this a reasonable feature request, or is it not really feasible?
> 
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> http://dev.eclipse.org/mailman/listinfo/aspectj-users
> 




Back to the top