4

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

tkruse
  • 10,222
  • 7
  • 53
  • 80

1 Answers1

2

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
Fred
  • 446
  • 3
  • 5
  • You are right. I tested this simple test case & it's working fine. However, when using complex objects as parameters, rather than String and int, it is always matching. My method signature is something like this (MyObject, boolean, String, MyObject1, MyObject2, MyObject3, MyObject3) – user2546541 Jul 04 '13 at 09:46
  • 1
    I found the problem. I have to specify the full class name of my objects for it to work. (a.b.MyObject, boolean, String, a.b.MyObject1, a.b.MyObject2, a.b.MyObject3, a.b.MyObject3) Thanks for your help Fred. Issue closed – user2546541 Jul 04 '13 at 10:13
  • Yes, the full class name is necessary if you use @AspectJ coding style. If you use native syntax, you do not need to do it because you can just import all classes used as usual in Java. – kriegaex Jul 10 '13 at 17:41