[
https://issues.apache.org/jira/browse/GROOVY-12676?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Paul King resolved GROOVY-12676.
--------------------------------
Fix Version/s: 7.0.0-alpha-1
6.0.1
Assignee: Paul King
Resolution: Fixed
> 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: 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 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)