This is an automated email from the ASF dual-hosted git repository.

garydgregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-lang.git

commit 0725484b1369578155d5b90ed6b3d7f882eb1283
Author: Gary Gregory <[email protected]>
AuthorDate: Sun Nov 15 16:41:06 2026 -0500

    Add regression test for cloning plugin-only proxies
    
    Compile an interface outside the application classpath and verify that
    SerializationUtils.clone() preserves the proxy class, deep-clones its
    handler, and supports interface method invocation.
    
    Confirm the test fails with ClassNotFoundException before the proxy
    resolution fix. Full offline Maven verification passes.
    
    Assisted-By: OpenAI Codex
---
 .../commons/lang3/SerializationUtilsTest.java      | 37 ++++++++++++++++++++++
 1 file changed, 37 insertions(+)

diff --git a/src/test/java/org/apache/commons/lang3/SerializationUtilsTest.java 
b/src/test/java/org/apache/commons/lang3/SerializationUtilsTest.java
index b6f9100b4..cd64055ac 100644
--- a/src/test/java/org/apache/commons/lang3/SerializationUtilsTest.java
+++ b/src/test/java/org/apache/commons/lang3/SerializationUtilsTest.java
@@ -44,13 +44,20 @@
 import java.lang.reflect.Proxy;
 import java.net.URL;
 import java.net.URLClassLoader;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.function.Supplier;
 
+import javax.tools.JavaCompiler;
+import javax.tools.ToolProvider;
+
 import org.apache.commons.lang3.reflect.testbed.Bar;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
 import org.junit.jupiter.params.ParameterizedTest;
 import org.junit.jupiter.params.provider.ValueSource;
 
@@ -276,6 +283,36 @@ protected Class<?> loadClass(final String name, final 
boolean resolve) throws Cl
         }
     }
 
+    @Test
+    void testCloneProxyWithPluginOnlyInterface(@TempDir final Path tempDir) 
throws Exception {
+        final String interfaceName = "plugin.CloneInterface";
+        final Path source = tempDir.resolve("CloneInterface.java");
+        Files.write(source, "package plugin; public interface CloneInterface { 
String value(); }".getBytes(StandardCharsets.UTF_8));
+        final JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
+        assertNotNull(compiler, "A JDK compiler is required to create the 
plugin-only interface");
+        final ByteArrayOutputStream diagnostics = new ByteArrayOutputStream();
+        assertEquals(0, compiler.run(null, diagnostics, diagnostics, "-d", 
tempDir.toString(), source.toString()),
+                diagnostics.toString(StandardCharsets.UTF_8.name()));
+        final ClassLoader applicationLoader = getClass().getClassLoader();
+        final Thread thread = Thread.currentThread();
+        final ClassLoader originalLoader = thread.getContextClassLoader();
+        try (URLClassLoader loader = new URLClassLoader(new URL[] { 
tempDir.toUri().toURL() }, null)) {
+            thread.setContextClassLoader(applicationLoader);
+            // Neither the application loader nor the context loader can 
resolve this interface by name.
+            assertThrows(ClassNotFoundException.class, () -> 
Class.forName(interfaceName, false, applicationLoader));
+            final Class<?> proxyInterface = Class.forName(interfaceName, 
false, loader);
+            final Serializable proxy = (Serializable) 
Proxy.newProxyInstance(loader, new Class<?>[] { proxyInterface }, new 
SerializableInvocationHandler());
+            final Serializable clone = SerializationUtils.clone(proxy);
+            assertNotSame(proxy, clone);
+            assertSame(proxy.getClass(), clone.getClass());
+            assertTrue(proxyInterface.isInstance(clone));
+            assertNotSame(Proxy.getInvocationHandler(proxy), 
Proxy.getInvocationHandler(clone));
+            assertEquals("test", 
proxyInterface.getMethod("value").invoke(clone));
+        } finally {
+            thread.setContextClassLoader(originalLoader);
+        }
+    }
+
     @Test
     void testCloneProxyWithPublicInterfaces() {
         final Serializable proxy = (Serializable) 
Proxy.newProxyInstance(getClass().getClassLoader(),

Reply via email to