[
https://issues.apache.org/jira/browse/GROOVY-12669?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18137523#comment-18137523
]
ASF GitHub Bot commented on GROOVY-12669:
-----------------------------------------
testlens-app[bot] commented on PR #3190:
URL: https://github.com/apache/groovy/pull/3190#issuecomment-6613099189
## ✅ All tests passed ✅
🏷️ Commit: 6350e385b1d76d42331d3d89170288622b0f559b
▶️ Tests: 122084 executed
⚪️ Checks: 27/27 completed
---
_Learn more about TestLens at
[testlens.app/docs](https://testlens.app/docs/features/pr-comment/)._
> Rehydrating or dehydrating a memoized closure keeps calling the original
> closure with its old owner and delegate
> ----------------------------------------------------------------------------------------------------------------
>
> Key: GROOVY-12669
> URL: https://issues.apache.org/jira/browse/GROOVY-12669
> Project: Groovy
> Issue Type: Bug
> Affects Versions: 4.0.33, 5.0.8, 7.0.0-alpha-1, 6.0.0
> Reporter: Scott Murphy Heiberg
> Priority: Major
>
> {code:groovy}
> class O { def foo() { 'o' } }
> class P { def foo() { 'p' } }
> def c = new O().with { o -> { x -> foo() + x } }
> assert c.rehydrate(null, new P(), new P()).memoize()(1) == 'p1'
> println c.memoize().rehydrate(null, new P(), new P())(1) // prints o1
> println c.memoizeAtMost(5).rehydrate(null, new P(), new P())(1) // prints o1
> new ObjectOutputStream(new
> ByteArrayOutputStream()).writeObject(c.memoize().dehydrate())
> {code}
> *Actual:* a rehydrated copy of {{memoize()}}, {{memoizeAtMost}},
> {{memoizeAtLeast}} or {{memoizeBetween}} prints {{o1}}. Serializing the
> dehydrated memoized closure fails with {{java.io.NotSerializableException:
> O}}.
> *Expected:* {{p1}}, as for rehydrate followed by memoize. The dehydrated
> memoized closure serializes.
> Cause: the memoized closure forwards calls to the closure it wraps, held in a
> separate field. The inherited {{rehydrate}} and {{dehydrate}} replace only
> the wrapper's own owner, delegate and this object, so the wrapped closure
> keeps the old ones. The copy also shares the original's cache. Related:
> GROOVY-12665 (the same for curried, writable, composed and trampolined
> closures).
> Verified on 4.0.33, 5.0.8, 6.0.0 and master.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)