Scott Murphy Heiberg created GROOVY-12676:
---------------------------------------------

             Summary: withObjectInputStream(ClassLoader) fails with 
ClassNotFoundException for serialized primitive classes such as int.class
                 Key: GROOVY-12676
                 URL: https://issues.apache.org/jira/browse/GROOVY-12676
             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 bytes = new ByteArrayOutputStream()
bytes.withObjectOutputStream { it.writeObject([int.class, void.class]) }
new 
ByteArrayInputStream(bytes.toByteArray()).withObjectInputStream(getClass().classLoader)
 { it.readObject() }

// also: a dehydrated closure with a primitive parameter, whose parameterTypes 
holds int.class
bytes = new ByteArrayOutputStream()
bytes.withObjectOutputStream { it.writeObject({ int x -> x + 1 }.dehydrate()) }
new 
ByteArrayInputStream(bytes.toByteArray()).withObjectInputStream(getClass().classLoader)
 { it.readObject() }
{code}
*Actual:* {{java.lang.ClassNotFoundException: int}}. The same applies to the 
File and Path variants, and to the {{clone()}} generated by 
{{@AutoClone(style=SERIALIZATION)}} for a class holding a primitive Class or 
such a closure.

*Expected:* {{[int, void]}} and a working closure, as with 
{{withObjectInputStream}} without a class loader.

Cause: {{IOGroovyMethods.newObjectInputStream(InputStream, ClassLoader)}} 
overrides {{ObjectInputStream.resolveClass}} with {{Class.forName}}, which 
cannot load primitive types. The JDK implementation falls back to a table of 
primitive types when {{Class.forName}} fails; the override has no such fallback.

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