theigl opened a new issue, #1854: URL: https://github.com/apache/fury/issues/1854
### Search before asking - [X] I had searched in the [issues](https://github.com/apache/fury/issues) and found no similar issues. ### Version Fury: 0.71 JDK: 21 ### Component(s) Java ### Minimal reproduce step ```java import org.apache.fury.Fury; import org.apache.fury.config.Language; import org.junit.jupiter.api.Test; import java.io.ObjectStreamException; import java.io.Serializable; import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; import java.lang.reflect.Proxy; import static org.junit.jupiter.api.Assertions.assertEquals; class ProxySerializerTest { @Test void serializeProxy() { final Fury fury = Fury.builder() .withLanguage(Language.JAVA) .requireClassRegistration(false) .build(); final Object o = ProxyFactory.createProxy(TestInterface.class); final byte[] s = fury.serialize(o); assertEquals(fury.deserialize(s), o); } interface TestInterface { void test(); } static class ProxyFactory { static <T> T createProxy(final Class<T> type) { return new JdkProxyFactory().createProxy(type); } static final class JdkProxyFactory { @SuppressWarnings("unchecked") <T> T createProxy(final Class<T> type) { final JdkHandler handler = new JdkHandler(type); try { final ClassLoader cl = Thread.currentThread().getContextClassLoader(); return (T) Proxy.newProxyInstance(cl, new Class[]{type, Serializable.class}, handler); } catch (IllegalArgumentException e) { throw new RuntimeException("Could not create proxy for type [" + type.getName() + "]", e); } } static class JdkHandler implements InvocationHandler, Serializable { private final String typeName; private JdkHandler(Class<?> type) { typeName = type.getName(); } @Override public Object invoke(Object proxy, Method method, Object[] args) { return null; } public Object writeReplace() throws ObjectStreamException { return new ProxyReplacement(typeName); } } static final class ProxyReplacement implements Serializable { private final String type; ProxyReplacement(final String type) { this.type = type; } private Object readResolve() throws ObjectStreamException { final Class<?> clazz; try { clazz = Class.forName(type, false, Thread.currentThread().getContextClassLoader()); } catch (ClassNotFoundException ex) { throw new RuntimeException(ex); } return ProxyFactory.createProxy(clazz); } } } } } ``` ### What did you expect to see? Serializable JDK proxies can be de-serialized. ### What did you see instead? The following exception is thrown: > java.lang.ClassCastException: class xyz.$Proxy8 cannot be cast to class java.lang.reflect.InvocationHandler The problem seems to be the `JdkProxySerializer` and the `ReplaceResolveSerializer` get in each other's way because the `InvocationHandler` implements `writeReplace`. ### Anything Else? _No response_ ### Are you willing to submit a PR? - [ ] I'm willing to submit a PR! -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
