Search code examples
aopaspectj

AspectJ Advice Defined but not applied


All, I have tried to find a solution to this but somehow it is illuding me. I am, on an experimental basis trying to instrument H2 driver to print out some traces. The aspects are as follows:

pointcut getMajorVersion_pointcut() :
    call(int org.h2.Driver.getMajorVersion());

before() : getMajorVersion_pointcut() {
    System.out.println("Before Advice:: driver executed");
}

This works perfectly and I get the output "Before Advice:: driver executed".

However, the other advice is making problems:

pointcut accept_pointcut(String url) :
    call(boolean org.h2.Driver.acceptsURL(String)) && args(url);

before(String url) : accept_pointcut(url) {
    System.out.println(url);
}

Eclipse is flagging "Advice defined in ... has not been applied"

The screenshot is given below:

enter image description here

As can be seen in the left panel, H2 driver has the method with the signature. Could anyone point me in the right direction.


Solution

  • Where is the code calling Driver.acceptsURL(String)? It must be somewhere in your woven (application) code. If the call is made from within the H2 library, it will not be intercepted because that code it outside the control of AspectJ. If you want to change that circumstance, you need to

    • either put the library on the inpath and weave the H2 classes, creating a woven version of the library and using it instead of the original one during runtime,
    • or use load-time weaving (LTW) and weave the H2 library on the fly during class-loading.