Scott Murphy Heiberg created GROOVY-12677:
---------------------------------------------

             Summary: 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: 5.0.8, 4.0.33, 6.0.0, 7.0.0-alpha-1
            Reporter: Scott Murphy Heiberg


{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