Announcement Announcement Module
Collapse
No announcement yet.
Not all methods of interface are advised Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Not all methods of interface are advised

    Example:

    Code:
    package foo;
    Interface A {
        public void testA();
        public void testB();
    }
    
    
    Class AImpl extends B implements A
    ...
    public void testA() {
        doSomething();
    }
    ...
    
    Class B
    ...
    public void testB() {
        doSomething();
    }
    ....
    We define a pointcut in an aspect on interface A (we use spring dynamic proxies):
    Code:
    execution(* foo.A+.*(..))
    It appears that only testA() method is advised and NOT testB().
    Can you provide a solution to define a pointcut for this class hierarchy that advises all methods on interface A?

  • #2
    I can only verify that this is true but I am not sure if it is correct or not.

    I also get this message in my log:
    "Unable to apply any optimizations on advised method: public void foo.testB()"
    I assume it does not mean that it is advised, only available to be advised?

    Adding "abstract B implements A" makes everything ok though (as expected).
    Does the class which actually contain the method have to implement A?

    What is the expected behavior here?

    Comment


    • #3
      It is indeed so that we have to use the class hiarchy as described in de code example. I don't understand why method testB() in class AImpl isn't advised? It is part of the interface A on which we have a poincut and it is part of AImpl through inheritance.

      Comment


      • #4
        That is a correct behavior though it looks unexpected. It's possible to call method testB() on the AImpl instance. However, the method is considered to belong to the B class, not A interface. You can check that easily via the following code:
        Code:
        System.out.println(AImpl.class.getMethod("testB").getDeclaringClass());
        Pointcut execution(* foo.A+.*(..)) selects all public methods of the classes that are IS-A A. However, testB() belongs to the class B for which B IS-A A is false. Hence, the testB() invocation is not mapped by the pointcut.

        Comment


        • #5
          Thanks, I begin to understand what they mean when they say that a problem with AOP is that it is based on classes...

          Comment

          Working...
          X