8 Replies Latest reply on Aug 17, 2005 9:30 AM by kabirkhan

    StackOverflow when trying to

      Hi there!
      I need help cause I cannot figure it out by myself. I got stackOverflow and don't know why... Here's the short code

      public void test(){
       TestRoot root = new TestRoot();
       ((Persistable)root).getObjectByOID(id);
      }


      Output:
      [junit] Testcase: testGetObjectByOID took 4,575 sec
       [junit] Caused an ERROR
       [junit] null
       [junit] java.lang.StackOverflowError
       [junit] at java.lang.Exception.<init>(Exception.java:77)
       [junit] at java.lang.reflect.InvocationTargetException.<init>(InvocationTargetException.java:54)
       [junit] at sun.reflect.GeneratedMethodAccessor2.invoke(Unknown Source)
       [junit] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       [junit] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:99)
       [junit] at org.jboss.aop.ClassAdvisor.invokeMethod(ClassAdvisor.java:1495)
       [junit] at org.jboss.aop.ClassAdvisor.invokeMethod(ClassAdvisor.java:1468)
       [junit] at org.nthx.pat.tests.TestRoot._added_m$0(TestRoot.java)
       [junit] at org.nthx.pat.tests.TestRoot.getObjectByOID(TestRoot.java)
       [junit] at sun.reflect.GeneratedMethodAccessor2.invoke(Unknown Source)
       [junit] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       [junit] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:99)
       [junit] at org.jboss.aop.ClassAdvisor.invokeMethod(ClassAdvisor.java:1495)
       [junit] at org.jboss.aop.ClassAdvisor.invokeMethod(ClassAdvisor.java:1468)
       [junit] at org.nthx.pat.tests.TestRoot._added_m$0(TestRoot.java)
       [junit] at org.nthx.pat.tests.TestRoot.getObjectByOID(TestRoot.java)
      ......and so on..
      



      My configurations:

      <introduction expr="class(@pat.root)">
       <interfaces>
       org.nthx.pat.Persistable
       </interfaces>
      </introduction>
      <bind pointcut="call(void $instanceof{org.nthx.pat.Persistable}->getObjectByOID(java.lang.Long))">
       <advice aspect="org.nthx.pat.PersistableAspect" name="getObjectByOID"/>
      </bind>
      
      @pat.root
      public class TestRoot{}
      
      public interface Persistable
      {
       public Identifiable getObjectByOID(Long OID);
      }
      
      public class PersistableAspect
      {
       public Object getObjectByOID(Invocation invocation) throws Throwable
       {
       return null;
       }
      }


      Any idea would be appreciated, cause I really don't know why is this happening. I see nothing making the loop ...

      Is it becase I cut a nonexistent method? There is no mixin here..

      Regards,
      Tomasz



        • 1. Re: StackOverflow when trying to
          kabirkhan

          You need to provide a mixin when your interface contains methods

          http://jira.jboss.com/jira/browse/JBAOP-71

          • 2. Re: StackOverflow when trying to

            Hi there Kabir!

            Well, I read the JIRA's issue. I completely agree with Bill here:

            The thing is, if you're just introducing an interface with no mixin, then an interceptor should handle the implementation.


            But hear this, cause that's more funny:
            'takeSnapshot' is another method from the interface. Similar pointcut exists, the same aspect, the same test case and call to
            ((Persistable)root).takeSnapshot();
            works!

            jboss-aop-1.3, no mixin for interface, aop config you see here, the same behavior for call/execution type...

            This is wired.. have any possible explanation for that behaviour?

            Thanks - Tomasz



            • 3. Re: StackOverflow when trying to
              kabirkhan

              Hi Tomasz,

              If you're still having problems, can you please send me a scaled down version of this to demonstrate the problem?

              Thanks

              • 4. Re: StackOverflow when trying to

                Yes, I still do have that problem.

                I prepared an archive with all unnecessary files removed from my project. It's stripped down version of Pat M1.09. The build process needs to make distros for jdk5 and jdk4, so don't look at 'build.xml' ;-).

                $ant tests (for jdk4, uses @@)
                $ant -Dnthx.is.java5=yes tests (requires jdk5, uses @)

                Archive sent on priv.

                Kind regards,
                Tomasz Nazar

                • 5. Re: StackOverflow when trying to
                  kabirkhan

                  Hi Tomasz,

                  The problem is your pointcut expression

                  <bind pointcut="execution(void @pat.root->getObjectByOID(java.lang.Long))">
                   <advice aspect="org.nthx.pat.PersistableAspect" name="getObjectByOID"/>
                  </bind>


                  A bit of digging reveals that Persistable.getObjectByOID() returns Identifiable, so the pointcut is never matched, meaning interception does not take place, which causes the recursion.

                  If I change the pointcut to

                  <bind pointcut="execution(org.nthx.pat.Identifiable @pat.root->getObjectByOID(java.lang.Long))">
                   <advice aspect="org.nthx.pat.PersistableAspect" name="getObjectByOID"/>
                  </bind>


                  it is fine.

                  Cheers,

                  Kabir

                  • 6. Re: StackOverflow when trying to
                    kabirkhan

                    PS sorry for the delay, I should have spotted this a lot sooner

                    • 7. Re: StackOverflow when trying to


                      Aaaaaa! ;-)

                      What a silly bug. Thanks for your time. :)

                      This happens when you "copy and paste"...

                      So few points here:
                      1. JBAOP should warn the pointcut doesn't exist, shouldn't it? (Instead of recursively calling itself)
                      2. Here the IDE could help by showing "No pointcuts matched". Is there any for IDEA? There is one for Eclipse, isn't it?

                      One more time: "thank you" -- what a silly bug :)

                      Tomasz

                      • 8. Re: StackOverflow when trying to
                        kabirkhan

                        1) I think if you use verbose mode you should get the warning during weaving about methods not matching any joinpoints

                        2) We currently have an IDE for Eclipse, but not for IDEA and I think it has some warnings like this. I was just trying out the latest IDE myself this morning, but I seemed to get hold of an older version. I'll let you know as soon as I know myself :-)