0

I was able to get the @AfterThrowing work for my basic needs

@AfterThrowing(pointcut = "within(@custom.SomeAnnotation *) || @annotation(custom.SomeAnnotation) ", throwing = "ex")
public void intercept(Throwable ex) {
    // do stuff
}

But when I try to read a field from the annotation I'm getting java.lang.IllegalArgumentException: error at ::0 inconsistent binding

I tried several approaches, the last one that I tried was:

@AfterThrowing(pointcut = "within(@custom.SomeAnnotation *) || @annotation(custom.SomeAnnotation) || @annotation(custom.SomeAnnotation(myProperty))", throwing = "ex", argNames = "ex, myProperty")
public void intercept(Throwable ex, String myProperty) {
    // do stuff
}

Am I using the pointcut correctly?

I tried

@AfterThrowing(pointcut = "within(@custom.SomeAnnotation *) || " +
            "@annotation(custom.SomeAnnotation) || " +
            "@annotation(custom.SomeAnnotation) && args(myProperty))",
            throwing = "ex", argNames = "ex, myProperty")

@AfterThrowing(pointcut = "@annotation(theAnnotation)",
throwing = "ex", argNames = "ex, theAnnotation")
public void intercept(Throwable ex, custom.SomeAnnotation theAnnotation) 
Rafael
  • 1
  • No, you are not using it correctly. If you have `A || B` (non-exclusive OR), either A or B or both could match, which is why the parameter binding is correctly identified as ambiguous. If both the class and the method are annotated, which one should the aspect bind? Just use multiple advice methods, bind the corresponding annotations and factor out the common code into a helper method taking all the parameters you need. Then you are free to manually hand over the bound annotations from both advices to the helper method using the same parameter. – kriegaex Nov 23 '22 at 07:04

0 Answers0