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

dashorst pushed a commit to branch WICKET-7204-regression
in repository https://gitbox.apache.org/repos/asf/wicket.git


The following commit(s) were added to refs/heads/WICKET-7204-regression by this 
push:
     new 76935f9795 Key the proxy class cache on the type's loader only, and 
test java.* proxies
76935f9795 is described below

commit 76935f9795d8cca0574a1b45995d211d81307a7d
Author: Martijn Dashorst <[email protected]>
AuthorDate: Wed Oct 28 10:44:23 2026 +0100

    Key the proxy class cache on the type's loader only, and test java.* proxies
    
    A non-java.* type on the bootstrap class loader cannot get a private
    lookup, so its proxy fails on that regardless of the class loader it is
    cached for; the fallback to the application's class loader for it is
    gone. isInternalJavaType becomes isInJavaPackage, because java.sql and
    java.net.http are not internal. The rationale on resolveClassLoader(Class)
    moves to the commit message, and a test proxies java.sql.Timestamp, whose
    platform class loader is the reason the java.* check in
    resolveClassLoader(Class) has to stay.
    
    Generated-by: Claude Code (Claude Opus 5.5)
---
 .../proxy/bytebuddy/ByteBuddyProxyFactory.java     | 42 ++++++----------------
 .../proxy/bytebuddy/ByteBuddyProxyFactoryTest.java | 22 +++++++++---
 2 files changed, 27 insertions(+), 37 deletions(-)

diff --git 
a/wicket-ioc/src/main/java/org/apache/wicket/proxy/bytebuddy/ByteBuddyProxyFactory.java
 
b/wicket-ioc/src/main/java/org/apache/wicket/proxy/bytebuddy/ByteBuddyProxyFactory.java
index a292bc2c31..45b1bb1d30 100644
--- 
a/wicket-ioc/src/main/java/org/apache/wicket/proxy/bytebuddy/ByteBuddyProxyFactory.java
+++ 
b/wicket-ioc/src/main/java/org/apache/wicket/proxy/bytebuddy/ByteBuddyProxyFactory.java
@@ -124,16 +124,12 @@ public class ByteBuddyProxyFactory implements 
IProxyFactory
        }
 
        /**
-        * {@code java.*} types cannot host a generated proxy: the JVM forbids 
defining classes in
-        * those packages, so they are renamed and loaded through a class 
loader of their own.
-        *
-        * @param prefix
-        *            fully qualified name of the type to proxy
-        * @return {@code true} when the type belongs to a {@code java.*} 
package
+        * The JVM does not allow a class to be defined in a <em>java.**</em> 
package, so the proxy for
+        * a type in one is renamed into another package.
         */
-       private static boolean isInternalJavaType(String prefix)
+       private static boolean isInJavaPackage(String typeName)
        {
-               return prefix.startsWith("java.");
+               return typeName.startsWith("java.");
        }
 
        /**
@@ -143,7 +139,7 @@ public class ByteBuddyProxyFactory implements IProxyFactory
         */
        private static ClassLoadingStrategy<ClassLoader> 
resolveLoadingStrategy(Class<?> type)
        {
-               if (isInternalJavaType(type.getName()))
+               if (isInJavaPackage(type.getName()))
                {
                        return 
ClassLoadingStrategy.Default.WRAPPER.allowExistingTypes();
                }
@@ -161,34 +157,16 @@ public class ByteBuddyProxyFactory implements 
IProxyFactory
        }
 
        /**
-        * Resolves the class loader the proxy class for the given type is 
defined in. It is also the
-        * class loader the proxy class is cached for.
-        * <p>
-        * Unless the type is a <em>java.**</em> one (see
-        * {@link #resolveLoadingStrategy(Class)}), the proxy class is defined 
by lookup in the class
-        * loader of the proxied type, no matter which class loader the current 
thread resolves. The
-        * cache has to be keyed on that same class loader: if it was keyed on 
the class loader of the
-        * current thread, another thread (e.g. a servlet container request 
thread, whose context class
-        * loader differs from the one of the thread that initialized the 
application) would miss the
-        * cached class and try to define it a second time in the class loader 
of the type, failing with
-        * a {@link LinkageError} (duplicate class definition).
-        *
-        * @param type
-        *            the type to proxy
-        * @return the class loader the proxy class is defined in and cached for
+        * The class loader the proxy for the given type is defined in, and 
cached for.
         */
        private static ClassLoader resolveClassLoader(Class<?> type)
        {
-               if (!isInternalJavaType(type.getName()))
+               if (isInJavaPackage(type.getName()))
                {
-                       ClassLoader typeClassLoader = type.getClassLoader();
-                       if (typeClassLoader != null)
-                       {
-                               return typeClassLoader;
-                       }
+                       return resolveClassLoader();
                }
 
-               return resolveClassLoader();
+               return type.getClassLoader();
        }
 
        private static ClassLoader resolveClassLoader()
@@ -248,7 +226,7 @@ public class ByteBuddyProxyFactory implements IProxyFactory
                        String packageName = prefix.substring(0, lastIdxOfDot);
                        String className = prefix.substring(lastIdxOfDot + 1);
                        String name = packageName + ".";
-                       if (isInternalJavaType(prefix))
+                       if (isInJavaPackage(prefix))
                        {
                                name = "bytebuddy_generated_wicket_proxy." + 
name + className;
                        }
diff --git 
a/wicket-ioc/src/test/java/org/apache/wicket/proxy/bytebuddy/ByteBuddyProxyFactoryTest.java
 
b/wicket-ioc/src/test/java/org/apache/wicket/proxy/bytebuddy/ByteBuddyProxyFactoryTest.java
index 9af2c5999f..333d87b966 100644
--- 
a/wicket-ioc/src/test/java/org/apache/wicket/proxy/bytebuddy/ByteBuddyProxyFactoryTest.java
+++ 
b/wicket-ioc/src/test/java/org/apache/wicket/proxy/bytebuddy/ByteBuddyProxyFactoryTest.java
@@ -16,12 +16,15 @@
  */
 package org.apache.wicket.proxy.bytebuddy;
 
+import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertSame;
 
 import java.net.URL;
 import java.net.URLClassLoader;
+import java.sql.Timestamp;
 
 import org.apache.wicket.proxy.util.ConcreteObject;
+import org.apache.wicket.proxy.util.MockObjectLocator;
 import org.junit.jupiter.api.Test;
 
 /**
@@ -30,11 +33,7 @@ import org.junit.jupiter.api.Test;
 class ByteBuddyProxyFactoryTest
 {
        /**
-        * The proxy class is defined in the class loader of the proxied type, 
so it must be cached
-        * for that class loader, whatever class loader the current thread 
resolves. Otherwise a
-        * thread with another context class loader (e.g. a servlet container 
request thread) does
-        * not find the cached class and tries to define it a second time, 
which fails with a
-        * {@link LinkageError} (duplicate class definition).
+        * A thread with another context class loader gets the proxy class that 
is already defined.
         */
        @Test
        void proxyClassIsReusedAcrossContextClassLoaders() throws Exception
@@ -58,4 +57,17 @@ class ByteBuddyProxyFactoryTest
                        thread.setContextClassLoader(original);
                }
        }
+
+       /**
+        * A type in a <em>java.**</em> package of the platform class loader, 
which cannot see the
+        * interfaces the proxy implements.
+        */
+       @Test
+       void proxiesTypeInJavaPackageOfPlatformClassLoader()
+       {
+               Timestamp proxy = new 
ByteBuddyProxyFactory().createProxy(Timestamp.class,
+                       new MockObjectLocator(new Timestamp(42)));
+
+               assertEquals(42, proxy.getTime());
+       }
 }

Reply via email to