Fix NPE when Thread.currentThread().getContextClassLoader is null.
@@ -28,7 +28,15 @@ public class KryoValueDecoder extends AbstractValueDecoder {
}
Input input = new Input(in);
Kryo kryo = (Kryo) KryoValueEncoder.kryoThreadLocal.get()[0];
- kryo.setClassLoader(Thread.currentThread().getContextClassLoader());
+ ClassLoader classLoader = KryoValueDecoder.class.getClassLoader();
+ Thread t = Thread.currentThread();
+ if (t != null) {
+ ClassLoader ctxClassLoader = t.getContextClassLoader();
+ if (ctxClassLoader != null) {
+ classLoader = ctxClassLoader;
+ }
+ }
+ kryo.setClassLoader(classLoader);
return kryo.readClassAndObject(input);
}
}
