Introduce setLoadedClassHandler method on CGLIB ReflectUtils
See gh-29295
This commit is contained in:
@@ -349,7 +349,9 @@ abstract public class AbstractClassGenerator<T> implements ClassGenerator {
|
||||
if (attemptLoad) {
|
||||
try {
|
||||
// SPRING PATCH BEGIN
|
||||
gen = Class.forName(getClassName(), true, classLoader);
|
||||
synchronized (classLoader) { // just in case
|
||||
gen = ReflectUtils.loadClass(getClassName(), classLoader);
|
||||
}
|
||||
// SPRING PATCH END
|
||||
return gen;
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.springframework.asm.Type;
|
||||
|
||||
@@ -63,6 +64,8 @@ public class ReflectUtils {
|
||||
|
||||
private static BiConsumer<String, byte[]> generatedClassHandler;
|
||||
|
||||
private static Consumer<Class<?>> loadedClassHandler;
|
||||
|
||||
// SPRING PATCH BEGIN
|
||||
static {
|
||||
// Resolve protected ClassLoader.defineClass method for fallback use
|
||||
@@ -550,6 +553,21 @@ public class ReflectUtils {
|
||||
Class.forName(className, true, loader);
|
||||
return c;
|
||||
}
|
||||
|
||||
public static void setLoadedClassHandler(Consumer<Class<?>> loadedClassHandler) {
|
||||
ReflectUtils.loadedClassHandler = loadedClassHandler;
|
||||
}
|
||||
|
||||
public static Class<?> loadClass(String className, ClassLoader classLoader) throws ClassNotFoundException {
|
||||
// Force static initializers to run.
|
||||
Class<?> clazz = Class.forName(className, true, classLoader);
|
||||
Consumer<Class<?>> handlerToUse = loadedClassHandler;
|
||||
if (handlerToUse != null) {
|
||||
handlerToUse.accept(clazz);
|
||||
}
|
||||
return clazz;
|
||||
}
|
||||
|
||||
// SPRING PATCH END
|
||||
|
||||
public static int findPackageProtected(Class[] classes) {
|
||||
|
||||
Reference in New Issue
Block a user