You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Paul King (Jira)" <ji...@apache.org> on 2022/02/03 22:35:01 UTC

[jira] [Closed] (GROOVY-3015) Seems like ClosureMetaClass#invokeMethod does not respect the interceptable nature of the owner/delegate

     [ https://issues.apache.org/jira/browse/GROOVY-3015?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Paul King closed GROOVY-3015.
-----------------------------

> Seems like ClosureMetaClass#invokeMethod does not respect the interceptable nature of the owner/delegate
> --------------------------------------------------------------------------------------------------------
>
>                 Key: GROOVY-3015
>                 URL: https://issues.apache.org/jira/browse/GROOVY-3015
>             Project: Groovy
>          Issue Type: Bug
>          Components: groovy-runtime
>    Affects Versions: 1.5.6
>         Environment: Windows XP
>            Reporter: Erick Erickson
>            Assignee: Eric Milles
>            Priority: Major
>             Fix For: 4.0.0-beta-1, 3.0.9
>
>          Time Spent: 40m
>  Remaining Estimate: 0h
>
> 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**************



--
This message was sent by Atlassian Jira
(v8.20.1#820001)