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:
Trustin Lee 2008-10-01 11:06:18 +00:00
parent 8d5d8fd172
commit 4376cd5a91
2 changed files with 11 additions and 5 deletions

View File

@ -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(

View File

@ -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();
} }
} }