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

2021-08-17 Thread Eric Milles (Jira)


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

Eric Milles updated GROOVY-3015:

Fix Version/s: 3.0.9

> 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.3.4#803005)


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

2020-01-27 Thread Paul King (Jira)


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

Paul King updated GROOVY-3015:
--
Fix Version/s: (was: 3.x)
   4.x

> 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
>Priority: Major
> Fix For: 4.x
>
>
> 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.3.4#803005)