From: skybber Date: Sun, 17 Mar 2019 08:26:09 +0000 (+0100) Subject: Control ctxClassLoader usage per thread X-Git-Tag: rel_3_25_0_ga~5^2 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=f1e12688218e3f47574946ccddbb8402798e3540;p=javassist.git Control ctxClassLoader usage per thread --- 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); }