[ 
https://issues.apache.org/jira/browse/GROOVY-12677?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18140004#comment-18140004
 ] 

ASF GitHub Bot commented on GROOVY-12677:
-----------------------------------------

paulk-asert closed pull request #3198: GROOVY-12677: serialize a memoized 
closure that has cached a null result
URL: https://github.com/apache/groovy/pull/3198




> 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
>            Priority: Major
>
> {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)

Reply via email to