3 Replies Latest reply on Aug 10, 2005 8:10 PM by ben.wang

    $instanceof not instrumenting as expected

    twundke

      I'm using AOP with JBossCache (cache=1.2.3, AOP=1.3.1), and am having an issue with certain classes not being advised. Here is the interface/class hierarchy and xml file.

      package com.generic.code;
      interface Base;
      class BaseImpl implements Base;
      
      package com.my.code;
      interface Sub extends Base;
      class SubImpl extends BaseImpl implements Sub;


      <?xml version="1.0" encoding="UTF-8"?>
      
      <aop>
       <prepare expr="field(* $instanceof{com.generic.code.Base}->*)" />
      </aop>

      So, what I would expect is that both BaseImpl and SubImpl would be advised (I'm using the aopc compiler rather than runtime instrumentation). However, I find that only BaseImpl is advised.

      Two solutions seem to exist; make SubImpl explicitly implement Base, or add the Sub interface to the AOP file. Neither of these is especially appealing in my situation.

      Are my expectations correct? The AOP reference documentation seems to imply that $instanceof works the same way as Java instanceof, which would mean that SubImpl really is an instance of Base, and hence should be advised.

      Is this a bug, or am I just doing something wrong?

      Tim.

        • 1. Re: $instanceof not instrumenting as expected
          kabirkhan

          I modified the instanceof tutorial as follows and that works

          public interface SomeInterface
          {
           void someMethod();
          }
          
          public interface Intermediate extends SomeInterface
          {
          
          }
          
          public class POJO implements Intermediate
          {
           public int x;
          
           public void someMethod()
           {
           System.out.println("someMethod");
           }
          
          }
          
          
          <?xml version="1.0" encoding="UTF-8"?>
          <aop>
          
           <bind pointcut="execution(void $instanceof{SomeInterface}->someMethod())">
           <interceptor class="SimpleInterceptor"/>
           </bind>
           <bind pointcut="field(* $instanceof{SomeInterface}->x)">
           <interceptor class="SimpleInterceptor"/>
           </bind>
          
          </aop>
          
          


          If I have missed something let me know. Maybe include a bit more information about what you have in your classes

          • 2. Re: $instanceof not instrumenting as expected
            twundke

            Kabir,
            The problem is that I'm using JBossCache, which simply requires that the classes are prepared, rather than assigning a specific interceptor myself. So perhaps this is a problem only with the prepare binding?

            Tim.

            • 3. Re: $instanceof not instrumenting as expected

              Tim,

              I have just tried it using aopc with your example. It works for me. I can see the impl class has been "aspectized", although I don't actually run the example.

              -Ben