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

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

testlens-app[bot] commented on PR #3202:
URL: https://github.com/apache/groovy/pull/3202#issuecomment-6613774103

   ## ✅ All tests passed ✅
   
   🏷️ Commit: 6fee3059fef2ff48788a7cac56dc8f1f27e99d37
   ▶️ Tests:  126684 executed
   ⚪️ Checks: 27/27 completed
   
   ---
   _Learn more about TestLens at 
[testlens.app/docs](https://testlens.app/docs/features/pr-comment/)._
   




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

Reply via email to