groovy
  1. groovy
  2. GROOVY-3015

Seems like ClosureMetaClass#invokeMethod does not respect the interceptable nature of the owner/delegate

    Details

    • Type: Bug Bug
    • Status: Open Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 1.5.6
    • Fix Version/s: 3.0
    • Component/s: groovy-runtime
    • Labels:
      None
    • Environment:
      Windows XP
    • Number of attachments :
      0

      Description

      Sample program and output. The closure and the method both call 'outer'
      which calls 'inner', but the closure does NOT trace the call to 'outer'

      See comments, including Jochen "blackdrag" Theodorou's at
      http://www.nabble.com/implementing-GroovyInterceptable-behaves-differently-in-closures-and-methods-td19072057.html

      ************program output

      Entering shouldTraceOuterAndInnerClosure
      Entering inner
      Leaving inner
      Leaving shouldTraceOuterAndInnerClosure

      Entering shouldTraceOuterAndInnerMethod
      Entering outer
      Entering inner
      Leaving inner
      Leaving outer
      Leaving shouldTraceOuterAndInnerMethod

      *************end program output

      ****************code starts
      import org.codehaus.groovy.runtime.StringBufferWriter
      import org.codehaus.groovy.runtime.InvokerHelper

      class Traceable implements GroovyInterceptable {
      private static int indent = 1
      Writer writer = new PrintWriter(System.out)
      Object invokeMethod(String name, Object args)

      { def result def metaClass = InvokerHelper.getMetaClass(this) writer.write("\n" + ' ' * indent + "Entering $name") ++indent result = metaClass.invokeMethod(this, name, args) --indent writer.write("\n" + ' ' * indent + "Leaving $name") return result }

      }

      class Whatever extends Traceable {
      int outer()

      { return inner() }

      int inner()

      { return 1 }

      def shouldTraceOuterAndInnerClosure =

      { return outer() }

      int shouldTraceOuterAndInnerMethod() { return outer() }

      }

      def log = new StringBuffer()
      def traceMe = new Whatever(writer : new StringBufferWriter(log))

      traceMe.shouldTraceOuterAndInnerClosure()

      traceMe.shouldTraceOuterAndInnerMethod()

      println log.toString()

      ****************program ends*************

        Issue Links

          Activity

          blackdrag blackdrag made changes -
          Field Original Value New Value
          Assignee Jochen Theodorou [ blackdrag ]
          Fix Version/s 2.0 [ 13489 ]
          blackdrag blackdrag made changes -
          Link This issue depends upon GROOVY-2503 [ GROOVY-2503 ]
          blackdrag blackdrag made changes -
          Component/s groovy-runtime [ 16250 ]

            People

            • Assignee:
              blackdrag blackdrag
              Reporter:
              Erick Erickson
            • Votes:
              1 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated: