[
https://issues.apache.org/jira/browse/GROOVY-12677?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Paul King resolved GROOVY-12677.
--------------------------------
Fix Version/s: 7.0.0-alpha-1
6.0.1
Assignee: Paul King
Resolution: Fixed
> A memoize() closure that has cached a null result cannot be serialized
> ----------------------------------------------------------------------
>
> Key: GROOVY-12677
> URL: https://issues.apache.org/jira/browse/GROOVY-12677
> Project: Groovy
> Issue Type: Bug
> Affects Versions: 4.0.33, 5.0.8, 5.1.3, 6.0.0
> Reporter: Scott Murphy Heiberg
> Assignee: Paul King
> Priority: Major
> Fix For: 7.0.0-alpha-1, 6.0.1
>
>
> {code:groovy}
> def m = { x -> null }.dehydrate().memoize()
> assert m(1) == null
> def bytes = new ByteArrayOutputStream()
> bytes.withObjectOutputStream { it.writeObject(m) } // fails here
> def copy = new
> ByteArrayInputStream(bytes.toByteArray()).withObjectInputStream(getClass().classLoader)
> { it.readObject() }
> assert copy(1) == null
> {code}
> *Actual:* {{java.io.NotSerializableException:
> org.codehaus.groovy.runtime.memoize.Memoize$MemoizeNullValue}}. The same
> closure serializes when its cached results are not null.
> *Expected:* the memoized closure serializes. The copy returns null for the
> cached arguments without calling the wrapped closure again.
> The memoizing closure stores a null result as a private place-holder,
> {{Memoize.MemoizeNullValue}}, which is not {{Serializable}}. The closure
> recognises the place-holder by identity, so a deserialized copy must also
> resolve back to the shared instance.
> Verified on 4.0.33, 5.0.8, 6.0.0 and master.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)