From f1e12688218e3f47574946ccddbb8402798e3540 Mon Sep 17 00:00:00 2001 From: skybber Date: Sun, 17 Mar 2019 09:26:09 +0100 Subject: [PATCH] Control ctxClassLoader usage per thread --- src/main/javassist/runtime/Desc.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/main/javassist/runtime/Desc.java b/src/main/javassist/runtime/Desc.java index c733b30d..9fbe8f22 100644 --- a/src/main/javassist/runtime/Desc.java +++ b/src/main/javassist/runtime/Desc.java @@ -34,10 +34,25 @@ public class Desc { */ public static boolean useContextClassLoader = false; + private static final ThreadLocal USE_CONTEXT_CLASS_LOADER_LOCALLY = new ThreadLocal() { + @Override + protected Boolean initialValue() { + return false; + } + }; + + public static void setUseContextClassLoaderLocally() { + USE_CONTEXT_CLASS_LOADER_LOCALLY.set(true); + } + + public static void resetUseContextClassLoaderLocally() { + USE_CONTEXT_CLASS_LOADER_LOCALLY.remove(); + } + private static Class getClassObject(String name) throws ClassNotFoundException { - if (useContextClassLoader) + if (useContextClassLoader || USE_CONTEXT_CLASS_LOADER_LOCALLY.get()) return Class.forName(name, true, Thread.currentThread().getContextClassLoader()); return Class.forName(name); } -- 2.39.5