[
https://issues.apache.org/jira/browse/GROOVY-12665?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18140000#comment-18140000
]
ASF GitHub Bot commented on GROOVY-12665:
-----------------------------------------
paulk-asert closed pull request #3186: GROOVY-12665: rehydrate and dehydrate
the closure that a curried, writable, composed or trampolined closure wraps
URL: https://github.com/apache/groovy/pull/3186
> rehydrate() on a curried, writable, composed or trampolined closure throws
> ClassCastException or ignores the new owner and delegate
> -----------------------------------------------------------------------------------------------------------------------------------
>
> Key: GROOVY-12665
> URL: https://issues.apache.org/jira/browse/GROOVY-12665
> Project: Groovy
> Issue Type: Bug
> Affects Versions: 4.0.33, 5.0.8, 5.1.3, 6.0.0
> Reporter: Scott Murphy Heiberg
> Priority: Major
>
> {code:groovy}
> class O { def foo() { 'o' } }
> class D { def foo() { 'd' } }
> def c = { x, y -> foo() + x + y }
> assert c.rehydrate(new D(), new O(), new O()).curry(1)(2) == 'o12' // passes
> assert c.curry(1).rehydrate(new D(), new O(), new O())(2) == 'o12' // fails
> {code}
> *Actual:* {{java.lang.ClassCastException: class O cannot be cast to class
> groovy.lang.Closure}}, thrown at {{CurriedClosure.getOwner}} from
> {{CurriedClosure.call}} (on 4.0.33 a MissingMethodException for O.doCall()).
> * {{c.curry(1).dehydrate()}} throws NullPointerException when called.
> * {{c.asWritable().rehydrate(...)}} throws the same ClassCastException.
> * For {{(c >> g).rehydrate(...)}} and {{c.trampoline().rehydrate(...)}} the
> new owner and delegate are ignored: {{foo()}} still resolves against the
> original owner.
> * {{dehydrate()}} on a composed or trampolined closure still holds the
> original owner, so the result cannot be serialized.
> *Expected:* rehydrating or dehydrating a wrapper closure behaves like
> rehydrating or dehydrating the closure it wraps and wrapping the copy.
> Cause: {{Closure.rehydrate}} and {{Closure.dehydrate}} replace only the
> wrapper's own owner, delegate and thisObject fields. {{CurriedClosure}} and
> {{Closure.WritableClosure}} keep the wrapped closure in owner, so it is
> overwritten. {{ComposedClosure}} and {{TrampolineClosure}} call through
> separate fields, so the wrapped closures are never rehydrated or dehydrated.
> Verified on 4.0.33, 5.0.8, 6.0.0 and master.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)