Pointcut for all methods of a class including inherited ones

3.1k views Asked by At

I am playing around with aop and aspectj and discovered an (for me) unexpected behavior.

In the aspectj-docs I found the following example-pointcut:

execution(public void Middle.*())

for the following class-definitions (I slightly changed the original example):

class Super {
    public void m() { ... }
}
class Middle extends Super {
}
class Sub extends Middle {
    @Override
    public void m() { ... }
}

The description of that exmaple states:

[The pointcut] picks out all method executions for public methods returning void and having no arguments that are either declared in, or inherited by, Middle, even if those methods are overridden in a subclass of Middle.

This example is working fine for me but if class Sub is not overriding m(), the method-calls from outside to m on a Sub-instance are not intercepted. Doesn't this violates the doc?

I had another problem with pointcuts in inhertied classes which is caused by the use of proxies. But in this case the use of a proxy cannot cause this behavior because the proxy should provide methods for all of the proxied class. Or did I missed something?

my aspect-definition:

@Aspect
public class MyAspect {
    @Before(value = "execution(* Middle.*(..))", argNames="joinPoint")
    public void myAdvice(JoinPoint joinPoint) {
        System.out.println("adviced: " + joinPoint.getSignature());
    }
}
0

There are 0 answers