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
    • 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

      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

          Erick Erickson created issue -
          Jochen Theodorou made changes -
          Field Original Value New Value
          Fix Version/s 2.0 [ 13489 ]
          Assignee Jochen Theodorou [ blackdrag ]
          Jochen Theodorou made changes -
          Link This issue depends upon GROOVY-2503 [ GROOVY-2503 ]
          Jochen Theodorou made changes -
          Component/s groovy-runtime [ 16250 ]
          Mark Thomas made changes -
          Project Import Sun Apr 05 13:32:57 UTC 2015 [ 1428240777691 ]
          Mark Thomas made changes -
          Workflow jira [ 12732025 ] Default workflow, editable Closed status [ 12743899 ]
          Mark Thomas made changes -
          Project Import Mon Apr 06 02:11:23 UTC 2015 [ 1428286283443 ]
          Mark Thomas made changes -
          Workflow jira [ 12973479 ] Default workflow, editable Closed status [ 12980666 ]
          Jochen Theodorou made changes -
          Assignee Jochen Theodorou [ blackdrag ]

            People

            • Assignee:
              Unassigned
              Reporter:
              Erick Erickson
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:

                Development