11 Replies Latest reply on Sep 23, 2004 3:29 PM by bill.burke

    findMethodByHash & "Unable to figure out calledmethod of a c

    marciodel

      Hi. I figured out what happen when the exception "java.lang.RuntimeException: Unable to figure out calledmethod of a caller pointcut" is thrown.

      I think the problem is that I am defining a call pointcut to an interface. But the method findMethodByHash will verify only the methods defined by the class and its superclasses. It does not try to find the method in the implemented interfaces.

      It is wrong to define a call pointcut to an interface?

      Thanks,

      Marcio Alves

        • 1. Re: findMethodByHash & Unable to figure out calledmethod of
          marciodel

          I have changed the method

          findMethodByHash
          and my code is working now. Is it a general solution?

          public static Method findMethodByHash(Class clazz, long hash) throws Exception
          {
          System.out.println("findMethodByHash " + clazz.getName());
          Method[] methods = clazz.getDeclaredMethods();
          for (int i = 0; i < methods.length; i++)
          {
          System.out.println("methodHash " + methods.getName() + " " + methodHash(methods));
          if (methodHash(methods) == hash) return methods;
          }
          System.out.println("clazz.getSuperclass() " + clazz.getSuperclass());
          if (clazz.getSuperclass() != null)
          {
          return findMethodByHash(clazz.getSuperclass(), hash);
          }

          Class[] intfs = clazz.getInterfaces();
          if(intfs != null || intfs.length != 0 ){
          for (int i = 0; i < intfs.length; i++) {
          Method result = findMethodByHash(intfs, hash);

          if(result != null)
          return result;
          }
          }

          return null;
          }

          Thanks,

          • 2. Re: findMethodByHash &
            bill.burke

            Your pointcut expression was incorrect. You must do

            call(* $instanceof{java.sql.Connection}->*(..))
            


            Unfortunately, $instanceof cannot take wildcards at this time.

            If this is it, let me know.

            Thanks,

            Bill

            • 3. Re: findMethodByHash &
              marciodel

              The problem is that I am defining:

              call(javax.microedition.io.*->*(..))

              There is an interface javax.microedition.io.Connection in the package. My class is using javax.wireless.messaging.MessageConnection that extends javax.microedition.io.Connection. The code in bold below is being changed by JBossAOP, for javax.wireless.messaging.MessageConnection extends javax.microedition.io.Connection. But the probrem is that resolveCallerMethodInfo can not find the method close() in javax.wireless.messaging.MessageConnection, for close() is declared in javax.microedition.io.Connection. Then the exception is thrown. The method findMethodByHash only tries to find the method in the superclass, but javax.wireless.messaging.MessageConnection is an interface and don't have superclasses. It only extends interfaces (Class.getInterfaces()).

              javax.wireless.messaging.MessageConnection conn....
              ...
              ...
              conn.close();

              Thanks,

              Marcio Alves

              • 4. Re: findMethodByHash &
                kevinconner

                Hiya Bill.

                The issue is that the findMethodByHash method assumes that the clazz argument is a class, in this case it is an interface. The bug is that the method being searched is in a super interface of the one being called, hence it is never found.

                I have a simple test case that reproduces it and a patch that is very similar to the one Marcio suggested.

                 public static Method findMethodByHash(Class clazz, long hash) throws Exception
                 {
                 Method[] methods = clazz.getDeclaredMethods();
                 for (int i = 0; i < methods.length; i++)
                 {
                 if (methodHash(methods) == hash) return methods;
                 }
                 if (clazz.isInterface())
                 {
                 final Class[] interfaces = clazz.getInterfaces() ;
                 final int numInterfaces = interfaces.length ;
                 for(int count = 0 ; count < numInterfaces ; count++)
                 {
                 final Method method = findMethodByHash(interfaces[count], hash) ;
                 if (method != null)
                 {
                 return method ;
                 }
                 }
                 }
                 else if (clazz.getSuperclass() != null)
                 {
                 return findMethodByHash(clazz.getSuperclass(), hash);
                 }
                 return null;
                 }
                


                • 5. Re: findMethodByHash &
                  kabirkhan

                  Hi,

                  Looks reasonable. Can you please post the testcase?

                  Cheers,

                  Kabir

                  • 6. Re: findMethodByHash &
                    kabirkhan

                    Or send it to me at kabir.khan a jboss.org

                    • 7. Re: findMethodByHash &
                      bill.burke

                      the bug is that he is using the AOP framework incorrectly. He must use $instanceof{}. But, $instanceof{} is not complete in that it needs to support wildcards and annotations which it does not now.

                      But, I'll add the fix to findMethodHash anyways.

                      Bill

                      • 8. Re: findMethodByHash &
                        kevinconner

                        I'll link it in to the basic.AOPTester and send the patch to you.

                        Kev

                        • 9. Re: findMethodByHash &
                          kevinconner

                          Sorry Bill, just noticed your posting.

                          The problem happens when you use $instanceof{}. If you do not use it then the call does not get intercepted.

                          Kev

                          • 10. Re: findMethodByHash &
                            marciodel

                            Bill, Kevin and Kabir, thank you for the help.

                            Best regards,

                            Marcio Alves

                            • 11. Re: findMethodByHash &
                              bill.burke

                              BTW, the fix to findMethodByHash is in CVS and will be in RC2 on Friday.

                              Bill