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;
|
private final ClassLoader classLoader;
|
||||||
|
|
||||||
CompactObjectInputStream(InputStream in) throws IOException {
|
CompactObjectInputStream(InputStream in) throws IOException {
|
||||||
this(in, Thread.currentThread().getContextClassLoader());
|
this(in, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
CompactObjectInputStream(InputStream in, ClassLoader classLoader) throws IOException {
|
CompactObjectInputStream(InputStream in, ClassLoader classLoader) throws IOException {
|
||||||
@ -71,8 +71,14 @@ class CompactObjectInputStream extends ObjectInputStream {
|
|||||||
return super.readClassDescriptor();
|
return super.readClassDescriptor();
|
||||||
case CompactObjectOutputStream.TYPE_NON_PRIMITIVE:
|
case CompactObjectOutputStream.TYPE_NON_PRIMITIVE:
|
||||||
String className = readUTF();
|
String className = readUTF();
|
||||||
Class<?> clazz =
|
Class<?> clazz;
|
||||||
Class.forName(className, true, classLoader);
|
if (classLoader == null) {
|
||||||
|
clazz = Class.forName(
|
||||||
|
className, true,
|
||||||
|
Thread.currentThread().getContextClassLoader());
|
||||||
|
} else {
|
||||||
|
clazz = Class.forName(className, true, classLoader);
|
||||||
|
}
|
||||||
return ObjectStreamClass.lookup(clazz);
|
return ObjectStreamClass.lookup(clazz);
|
||||||
default:
|
default:
|
||||||
throw new StreamCorruptedException(
|
throw new StreamCorruptedException(
|
||||||
|
@ -119,7 +119,7 @@ public class ObjectDecoder extends FrameDecoder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
buffer.skipBytes(4);
|
buffer.skipBytes(4);
|
||||||
return new CompactObjectInputStream(new ChannelBufferInputStream(
|
return new CompactObjectInputStream(
|
||||||
buffer, dataLen), classLoader).readObject();
|
new ChannelBufferInputStream(buffer, dataLen), classLoader).readObject();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user