2

I have stumped myself with a problem involving Aspectj. What I am looking to do is have an "after() throwing" match against a call annotated with a method-level annotation.

@MyAnnotation    
public void doSomething(Param p1, Param p2)

If I use

after() throwing(MyCustomException ex) : call (@com.me.MyAnnotation * *.*(..))

It works, however if I have add some parameters to my annotation then they do not get matched.

@MyAnnotation(value = "doobery")    
public void doSomething(Param p1, Param p2)

What am I missing from my pointcut??

Just to clarify, I would like to match both examples and I don't care for the parameters in the annotation either.

Version of AspectJ 1.6

  • What version of AspectJ are you using? – Frank Pavageau Dec 05 '12 at 20:59
  • The complete version would be even more helpful :-) There's been some work around annotation parameters in recent versions, so it might have an impact, as it should work the way you've written it. If you don't get an answer here, you'll definitely get one on the aspect-users mailing list. – Frank Pavageau Dec 05 '12 at 21:20
  • 1.6.12 - What is interesting is that I turned on the weave debug and I can some methods in the class ARE getting weaved whereas others are being ignored.. Search goes on. – James 'Cookie' Cook Dec 05 '12 at 21:40

1 Answers1

2

Ha! got it.

So the clue was seeing the trace out of what was being weaved. I could see some methods getting weaved and others not. But it was the duplication of the weave on methods that i had the break through.

I was using "call" - Thus the weave was only happening on calls of the method, so when I had a class being weaved with multiple calls to the matching methods they would appear multiple times.

I needed to switch to "execution" so that the weave would happen on methods even if they weren't being called.

Chaned my advice to:

after() throwing(MyCustomException ex) : execution (@com.me.MyAnnotation * *(..))