Scott Murphy Heiberg created GROOVY-12681:
---------------------------------------------
Summary: withObjectInputStream(ClassLoader) and
newObjectInputStream(ClassLoader) do not use the given class loader for the
interfaces of a serialized Proxy
Key: GROOVY-12681
URL: https://issues.apache.org/jira/browse/GROOVY-12681
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}
import java.lang.reflect.Proxy
def gcl = new GroovyClassLoader()
def i = gcl.parseClass('interface Greeter { String greet() }')
def h = gcl.parseClass('''class H implements
java.lang.reflect.InvocationHandler, Serializable {
Object invoke(Object p, java.lang.reflect.Method m, Object[] a) { 'hi' }
}''')
def proxy = Proxy.newProxyInstance(gcl, [i] as Class[],
h.getDeclaredConstructor().newInstance())
def bytes = new ByteArrayOutputStream()
bytes.withObjectOutputStream { it.writeObject(proxy) }
println new
ByteArrayInputStream(bytes.toByteArray()).withObjectInputStream(gcl) {
it.readObject().greet() }
{code}
*Actual:* {{java.lang.ClassNotFoundException: Greeter}}. A plain instance of
{{H}} reads back fine through the same loader.
*Expected:* prints {{hi}}; the proxy's interfaces resolve through the given
class loader, like every other class in the stream.
The stream returned by {{IOGroovyMethods.newObjectInputStream(InputStream,
ClassLoader)}} overrides {{resolveClass}} but not {{resolveProxyClass}}. The
JDK default resolves proxy interfaces through the latest user-defined loader on
the call stack, which here is the script's loader. All class-loader variants on
InputStream, File and Path go through this method. Related: GROOVY-12676.
Verified on 4.0.33, 5.0.8, 6.0.0 and master.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)