3333 */
3434public abstract class AbstractThreadLocalContext <T > implements Context <T > {
3535 /**
36- * The constant of ThreadLocal context instances per subclass so different types don't get mixed.
36+ * The constant of ThreadLocal context instances per subclass name so different types don't get mixed.
3737 */
38- private static final ConcurrentMap <Class <?> , ThreadLocal <?>> INSTANCES =
39- new ConcurrentHashMap <Class <?> , ThreadLocal <?>>();
38+ private static final ConcurrentMap <String , ThreadLocal <?>> INSTANCES =
39+ new ConcurrentHashMap <String , ThreadLocal <?>>();
4040
4141 @ SuppressWarnings ("unchecked" )
4242 private final ThreadLocal <AbstractThreadLocalContext <T >> sharedThreadLocalContext = threadLocalInstanceOf ((Class ) getClass ());
@@ -148,7 +148,8 @@ protected static <T, CTX extends AbstractThreadLocalContext<T>> ThreadLocal<CTX>
148148 final Class <? extends CTX > contextType ) {
149149 if (contextType == null ) throw new NullPointerException ("The context type was <null>." );
150150 Class <?> type = contextType ;
151- if (!INSTANCES .containsKey (type )) {
151+ String typeName = type .getName ();
152+ if (!INSTANCES .containsKey (typeName )) {
152153 if (!AbstractThreadLocalContext .class .isAssignableFrom (type )) {
153154 throw new IllegalArgumentException ("Not a subclass of AbstractThreadLocalContext: " + type + '.' );
154155 } else if (Modifier .isAbstract (contextType .getModifiers ())) {
@@ -157,11 +158,12 @@ protected static <T, CTX extends AbstractThreadLocalContext<T>> ThreadLocal<CTX>
157158 // Find the first non-abstract subclass of AbstractThreadLocalContext.
158159 while (!Modifier .isAbstract (type .getSuperclass ().getModifiers ())) {
159160 type = type .getSuperclass ();
161+ typeName = type .getName ();
160162 }
161163 // Atomically get-or-create the appropriate ThreadLocal instance.
162- if (!INSTANCES .containsKey (type )) INSTANCES .putIfAbsent (type , new ThreadLocal ());
164+ if (!INSTANCES .containsKey (type . getName ())) INSTANCES .putIfAbsent (typeName , new ThreadLocal ());
163165 }
164- return (ThreadLocal <CTX >) INSTANCES .get (type );
166+ return (ThreadLocal <CTX >) INSTANCES .get (typeName );
165167 }
166168
167169 @ SuppressWarnings ("unchecked" )
0 commit comments