groovy
  1. groovy
  2. GROOVY-4892

GroovyInterceptable / invokeMethod does not correctly in Groovy 1.8.0 when Methods with no arguments are "delegated"

    Details

    • Number of attachments :
      0

      Description

      please compare
      http://stackoverflow.com/questions/6419674/groovyinterceptable-does-not-work-on-methods-with-no-arguments

      the following class gives the correct output in Groovy < 1.8, in 1.8 it only works if a parameter is added to the nested method.

      A workaround is mentioned in the stackoverflow link.

      class SimpleFlow implements GroovyInterceptable {
      
          def invokeMethod(String name, args) {
              System.out.println("time before ${name} called: ${new Date()}")
      
              def calledMethod = SimpleFlow.metaClass.getMetaMethod(name, args)
              calledMethod?.invoke(this, args)
      
              System.out.println("time after ${name} called: ${new Date()}\n")
          }
      
          void simpleMethod1(){
              System.out.println("simpleMethod1() called")
              simpleMethod2Nested()
          }
      
          // works well when using an argument
          void simpleMethod2Nested(){
              System.out.println("simpleMethod2Nested")
          }
      
          public static void main(String[] args) {
              def flow = new SimpleFlow()
              flow.simpleMethod1()
          }
      }
      

      actual output:

      time before simpleMethod1 called: Tue Jun 21 04:16:41 CEST 2011
      simpleMethod1() called
      simpleMethod2Nested
      time after simpleMethod1 called: Tue Jun 21 04:16:41 CEST 2011

      estimated output:
      time before simpleMethod1 called: Tue Jun 21 13:32:44 GMT+08:00 2011
      simpleMethod1() called
      time before simpleMethod2Nested called: Tue Jun 21 13:32:44 GMT+08:00 2011
      simpleMethod2Nested
      time after simpleMethod2Nested called: Tue Jun 21 13:32:44 GMT+08:00 2011
      time after simpleMethod1 called: Tue Jun 21 13:32:44 GMT+08:00 2011

        Activity

        Hide
        blackdrag blackdrag added a comment -

        changed formatting

        Show
        blackdrag blackdrag added a comment - changed formatting
        Hide
        blackdrag blackdrag added a comment -

        I change the priority to blocker, since it looks like the method optimizations simply ignore the GroovyInterceptable interface atm

        Show
        blackdrag blackdrag added a comment - I change the priority to blocker, since it looks like the method optimizations simply ignore the GroovyInterceptable interface atm
        Hide
        blackdrag blackdrag added a comment -

        fixed

        Show
        blackdrag blackdrag added a comment - fixed

          People

          • Assignee:
            blackdrag blackdrag
            Reporter:
            Al Calim
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: