Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-3015

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

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.5.6
    • 4.0.0-beta-1, 3.0.9
    • groovy-runtime
    • None
    • 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*************

      Attachments

        Issue Links

          Activity

            People

              emilles Eric Milles
              erickerickson Erick Erickson
              Votes:
              1 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 40m
                  40m