resolves issue: ClassNotFoundException thrown during SeriazliationCodec.decode #2136

pull/2138/head
Zhelyazko Chobantonov 6 years ago
parent 72ba19756d
commit f62f028e08

@ -39,15 +39,23 @@ public class SerializationCodec extends BaseCodec {
private final Decoder<Object> decoder = new Decoder<Object>() { private final Decoder<Object> decoder = new Decoder<Object>() {
@Override @Override
public Object decode(ByteBuf buf, State state) throws IOException { public Object decode(ByteBuf buf, State state) throws IOException {
try {
//set thread context class loader to be the classLoader variable as there could be reflection
//done while reading from input stream which reflection will use thread class loader to load classes on demand
ClassLoader currentThreadClassLoader = Thread.currentThread().getContextClassLoader();
try { try {
ByteBufInputStream in = new ByteBufInputStream(buf); ByteBufInputStream in = new ByteBufInputStream(buf);
ObjectInputStream inputStream; ObjectInputStream inputStream;
if (classLoader != null) { if (classLoader != null) {
Thread.currentThread().setContextClassLoader(classLoader);
inputStream = new CustomObjectInputStream(classLoader, in); inputStream = new CustomObjectInputStream(classLoader, in);
} else { } else {
inputStream = new ObjectInputStream(in); inputStream = new ObjectInputStream(in);
} }
return inputStream.readObject(); return inputStream.readObject();
} finally {
Thread.currentThread().setContextClassLoader(currentThreadClassLoader);
}
} catch (IOException e) { } catch (IOException e) {
throw e; throw e;
} catch (Exception e) { } catch (Exception e) {

@ -275,9 +275,18 @@ public class TasksRunnerService implements RemoteExecutorService {
T task; T task;
if (params.getLambdaBody() != null) { if (params.getLambdaBody() != null) {
ByteArrayInputStream is = new ByteArrayInputStream(params.getLambdaBody()); ByteArrayInputStream is = new ByteArrayInputStream(params.getLambdaBody());
//set thread context class loader to be the classLoaderCodec.getClassLoader() variable as there could be reflection
//done while reading from input stream which reflection will use thread class loader to load classes on demand
ClassLoader currentThreadClassLoader = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(classLoaderCodec.getClassLoader());
ObjectInput oo = new CustomObjectInputStream(classLoaderCodec.getClassLoader(), is); ObjectInput oo = new CustomObjectInputStream(classLoaderCodec.getClassLoader(), is);
task = (T) oo.readObject(); task = (T) oo.readObject();
oo.close(); oo.close();
} finally {
Thread.currentThread().setContextClassLoader(currentThreadClassLoader);
}
} else { } else {
task = (T) classLoaderCodec.getValueDecoder().decode(stateBuf, null); task = (T) classLoaderCodec.getValueDecoder().decode(stateBuf, null);
} }

Loading…
Cancel
Save