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

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

commit 4d47a713f34a802a088630c7ec9ca9284e2a18ad
Author: Andrea Del Bene <[email protected]>
AuthorDate: Mon Sep 7 16:21:03 2026 +0200

    WICKET-7204 Don't use INJECTION for ByteBuddy proxy creation
---
 pom.xml                                            |  2 +-
 .../proxy/bytebuddy/ByteBuddyProxyFactory.java     | 26 ++++++++++++++++++++--
 2 files changed, 25 insertions(+), 3 deletions(-)

diff --git a/pom.xml b/pom.xml
index af4192f148..31572c154a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -159,7 +159,7 @@
                <aspectj.version>1.9.25.1</aspectj.version>
                <assertj-core.version>3.27.7</assertj-core.version>
                <bouncycastle.version>1.85.2</bouncycastle.version>
-               <byte-buddy.version>1.18.8</byte-buddy.version>
+               <byte-buddy.version>1.18.13</byte-buddy.version>
                <cdi-unit.version>5.0.0-EA7</cdi-unit.version>
                
<commons-collections4.version>4.6.0</commons-collections4.version>
                
<commons-fileupload.version>2.0.0-M5</commons-fileupload.version>
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 307786d9d4..d75f6815e7 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
@@ -17,8 +17,10 @@
 package org.apache.wicket.proxy.bytebuddy;
 
 import java.io.Serializable;
+import java.lang.invoke.MethodHandles;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Modifier;
 import java.util.function.Function;
 
 import org.apache.wicket.Application;
@@ -100,8 +102,10 @@ public class ByteBuddyProxyFactory implements IProxyFactory
 
        @SuppressWarnings("unchecked")
        public static <T> Class<T> createOrGetProxyClass(Class<T> type)
-       {
+       {               
+               ClassLoadingStrategy<ClassLoader> loadingStrategy = 
resolveLoadingStrategy(type);
                ClassLoader classLoader = resolveClassLoader();
+               
                return (Class<T>) DYNAMIC_CLASS_CACHE.findOrInsert(classLoader,
                                new TypeCache.SimpleKey(type),
                                () -> BYTE_BUDDY
@@ -116,10 +120,26 @@ public class ByteBuddyProxyFactory implements 
IProxyFactory
                                                
.implement(InterceptorMutator.class).intercept(FieldAccessor.ofBeanProperty())
                                                .implement(Serializable.class, 
IWriteReplace.class, 
ILazyInitProxy.class).intercept(MethodDelegation.toField(INTERCEPTOR_FIELD_NAME))
                                                .make()
-                                               .load(classLoader, 
ClassLoadingStrategy.Default.INJECTION.allowExistingTypes())
+                                               .load(classLoader, 
loadingStrategy)
                                                .getLoaded());
        }
 
+       private static ClassLoadingStrategy<ClassLoader> 
resolveLoadingStrategy(Class<?> type) 
+       {
+               try 
+               {
+                       int modifiers = type.getModifiers();
+                       
+                       return !Modifier.isPublic(modifiers)
+                                  ? 
ClassLoadingStrategy.UsingLookup.of(MethodHandles.privateLookupIn(type, 
MethodHandles.lookup())) 
+                                  : 
ClassLoadingStrategy.Default.WRAPPER.allowExistingTypes();
+               } 
+               catch (IllegalAccessException e) 
+               {
+                       throw new WicketRuntimeException(e);
+               }
+       }
+
        private static ClassLoader resolveClassLoader()
        {
                ClassLoader classLoader = null;
@@ -205,7 +225,9 @@ public class ByteBuddyProxyFactory implements IProxyFactory
                for (Constructor<?> constructor : 
type.getDeclaredConstructors())
                {
                        if (constructor.getParameterTypes().length == 0)
+                       {
                                return true;
+                       }
                }
 
                return false;

Reply via email to