2 Replies Latest reply on Jul 11, 2005 4:27 PM by oberon777

    null returned

    oberon777

      I am using invocation.invokeNext() for caller invocations to capture the return result of the method being intercepted. However, it appears that that value is null.

      The pointcut in question is

       <bind pointcut="call(* java.lang.Class->newInstance(..))">
       <interceptor class="CallerInterceptor"/>
       </bind>
      


      I don't think exceptions are being thrown. Any thoughts?

        • 1. Re: null returned
          kabirkhan

          I am sure we have tests in our testsuite for this. In any case I gave it a go, and it worked for me.

          public class ConstructorInterceptor implements Interceptor
          {
           public String getName() { return "ConstructorInterceptor"; }
          
           public Object invoke(Invocation invocation) throws Throwable
           {
           try
           {
           System.out.println("<<< Doing it");
           Object o = invocation.invokeNext();
           System.out.println("Got o " + (o != null));
           return o;
           }
           finally
           {
           System.out.println(">>> Leaving ConstructorInterceptor");
           }
           }
          }
          



          <aop>
          
           <bind pointcut="call(* java.lang.Class->newInstance(..))">
           <interceptor class="ConstructorInterceptor"/>
           </bind>
          
          </aop>
          



          public class Driver
          {
           public static void main(String[] args) throws Exception
           {
           Class clazz = POJO.class;
           System.out.println("--- new POJO(); ---");
           POJO pojo = (POJO)clazz.newInstance();
           System.out.println("Got pojo " + (pojo != null));
           }
          }
          




          <?xml version="1.0" encoding="UTF-8"?>
          <aop>
          
           <bind pointcut="call(* java.lang.Class->newInstance(..))">
           <interceptor class="ConstructorInterceptor"/>
           </bind>
          
          </aop>
          



          Output:
          
           [java] --- new POJO(); ---
           [java] <<< Doing it
           [java] empty constructor
           [java] Got o true
           [java] >>> Leaving ConstructorInterceptor
           [java] Got pojo true
          


          • 2. Re: null returned
            oberon777

            Hmm.. thanks for such a detailed reply. I'll experiment some more to see what was causing this issue.