Question

I am trying to capture a method signature change and throw an error when it happens. But the declare error is not working as expected

@DeclareError("call(* a.b.C.method(..)) && !call(* a.b.C.method(int))")
public static final String errorMsg= "Signature error";

This is always matching the call to this method.

But if I move this pointcut to @Before, then it will not match unless the method signature has changed.

Any idea on why the different behavior between @DeclareError & @Before concerning the pointcuts ?

Thanks

Was it helpful?

Solution

strange - it works in my environment. (Eclipse with AspectJ Plugin)

@Aspect
public class GetNameOverrider {

    @DeclareError("call(* a.b.C.method(..)) && !call(* a.b.C.method(int))")
    static final String errorMsg= "Signature error";
}

gives me an Error at compile time if I do:

a.b.C c = new a.b.C();
c.method(new Integer(2)); <--- no Error
c.method(2); <--- no Error
c.method("test"); <--- Error

=============================

ErrorDescription    Resource    Path    Location    Type
"Signature error"   Main.java   /Stackoverflow/src/test line 12 AspectJ Problem
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top