[
https://issues.apache.org/jira/browse/GROOVY-3948?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15223579#comment-15223579
]
John Wagenleitner commented on GROOVY-3948:
-------------------------------------------
Added a test to try to prevent future regression:
https://github.com/apache/groovy/commit/c04e4df42ca3ed25570acc730d87807012c39887
> Replacing method on ExpandoMetaClass doesn't work
> -------------------------------------------------
>
> Key: GROOVY-3948
> URL: https://issues.apache.org/jira/browse/GROOVY-3948
> Project: Groovy
> Issue Type: Bug
> Components: groovy-runtime
> Affects Versions: 1.6.7
> Environment: Groovy Shell (1.6.7, JVM: 1.5.0_20)
> Reporter: Lajos Papp
> Fix For: 2.2.0
>
>
> {code}
> Expando.metaClass.foo={-> def directBar=delegate.bar()
> println "directBar=${directBar}"
> def invokedBar=delegate.invokeMethod('bar',null)
> println "invokedBar=$invokedBar"
> }
> e=new Expando()
> e.metaClass.bar={->1}
> e.foo()
> //directBar=1
> //invokedBar=1
> e.metaClass.bar={->2}
> e.foo()
> //directBar=1
> //invokedBar=2
> {code}
> for some reason delegate.bar() != delegate.invokeMethod('bar',null)
> looks like at the direct call the closure got cached ...
> if the previous example continues with:
> {code}
> x=new Expando()
> x.metaClass.bar={->3}
> e.foo()
> //directBar=2
> //invokedBar=2
> {code}
> creating the new 'x' object has side effect on the 'e' objects metaclass?
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)