Question

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

Was it helpful?

Solution

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 * *(..))
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top