Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[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?



Back to the top