Fixed a bug: NETTY-53 (ClassNotFoundException when an ObjectDecoder with no ClassLoader specified tries to decode an object.)
* Explicitly acquired the current thread's context class loader if a user specified no or null class loader.
This commit is contained in:
parent
8d5d8fd172
commit
4376cd5a91
@ -41,7 +41,7 @@ class CompactObjectInputStream extends ObjectInputStream {
|
||||
private final ClassLoader classLoader;
|
||||
|
||||
CompactObjectInputStream(InputStream in) throws IOException {
|
||||
this(in, Thread.currentThread().getContextClassLoader());
|
||||
this(in, null);
|
||||
}
|
||||
|
||||
CompactObjectInputStream(InputStream in, ClassLoader classLoader) throws IOException {
|
||||
@ -71,8 +71,14 @@ class CompactObjectInputStream extends ObjectInputStream {
|
||||
return super.readClassDescriptor();
|
||||
case CompactObjectOutputStream.TYPE_NON_PRIMITIVE:
|
||||
String className = readUTF();
|
||||
Class<?> clazz =
|
||||
Class.forName(className, true, classLoader);
|
||||
Class<?> clazz;
|
||||
if (classLoader == null) {
|
||||
clazz = Class.forName(
|
||||
className, true,
|
||||
Thread.currentThread().getContextClassLoader());
|
||||
} else {
|
||||
clazz = Class.forName(className, true, classLoader);
|
||||
}
|
||||
return ObjectStreamClass.lookup(clazz);
|
||||
default:
|
||||
throw new StreamCorruptedException(
|
||||
|
@ -119,7 +119,7 @@ public class ObjectDecoder extends FrameDecoder {
|
||||
}
|
||||
|
||||
buffer.skipBytes(4);
|
||||
return new CompactObjectInputStream(new ChannelBufferInputStream(
|
||||
buffer, dataLen), classLoader).readObject();
|
||||
return new CompactObjectInputStream(
|
||||
new ChannelBufferInputStream(buffer, dataLen), classLoader).readObject();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user