Skip to content

Commit af7547b

Browse files
committed
fix: getClassLoader() may return null
In the Java 8 + WAR + Tomcat runtime environment, when using CompletableFuture.runAsync() (which runs in ForkJoinPool), Thread.currentThread().getContextClassLoader() may return null. Meanwhile, SerializerFactory#getClassFactory only creates a ClassFactory instance on its first invocation. If the first Dubbo call happens to be executed in ForkJoinPool, ClassFactory._loader will be initialized as null and will remain null permanently. As a result, all subsequent Dubbo calls will fail during deserialization (objects will be converted to HashMap). Therefore, if classLoader is null at this point, it is better to throw an exception immediately to prevent ClassFactory from being initialized incorrectly.
1 parent 36cef60 commit af7547b

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

dubbo-serialization/dubbo-serialization-hessian2/src/main/java/org/apache/dubbo/common/serialize/hessian2/Hessian2SerializerFactory.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,12 @@ public Hessian2SerializerFactory() {
2525

2626
@Override
2727
public ClassLoader getClassLoader() {
28-
return Thread.currentThread().getContextClassLoader();
28+
ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
29+
if (contextClassLoader == null) {
30+
throw new IllegalStateException("context class loader is null");
31+
}
32+
33+
return contextClassLoader;
2934
}
3035

3136
}

0 commit comments

Comments
 (0)