Details
-
Bug
-
Status: Resolved
-
Major
-
Resolution: Fixed
-
2.0.7
-
None
-
None
-
Win 7, Java 7, MINA jars wrapped in NetBeans module.
Description
Using ObjectSerializationEncoder causes a lot of ClassNotFoundExceptions in AbstractIoBuffer.putObject().
In putObject() is Class.forName(String className) used for supporting the serialization process. This uses the Classloader of the calling thread. There is no guarantee that the calling thread is able to load all classes that should be serialized. Instead of using the caller thread Classloader the Thread.currentThread().getContextClassLoader() shoud be used to do the job, or the Classloade which should be used has to be passed in Constructor of ObjectSerializationEncoder, same way the ObjectSerializationDecoder does.
When using MINA in a modular Container like NetBeans the Thread.currentThread().getContextClassLoader() can be used inside without any API change.
Please consider this change for 2.0.8.
See appended code of AbstractIoBuffer.putObject() which works in NetBeans modular framework:
public IoBuffer putObject(Object o) {
int oldPos = position();
skip(4); // Make a room for the length field.
try {
ObjectOutputStream out = new ObjectOutputStream(asOutputStream()) {
@Override
protected void writeClassDescriptor(ObjectStreamClass desc) throws IOException {
try {
if (!desc.forClass().isArray()) {
Class<?> clz = Thread.currentThread().getContextClassLoader().loadClass(desc.getName());
if (!Serializable.class.isAssignableFrom(clz))
else
{ // Serializable class write(1); writeUTF(desc.getName()); }} else
{ write(0); super.writeClassDescriptor(desc); }} catch (ClassNotFoundException ex)
{ // Primitive types write(0); super.writeClassDescriptor(desc); } }
};
out.writeObject(o);
out.flush();
} catch (IOException e)
// Fill the length field
int newPos = position();
position(oldPos);
putInt(newPos - oldPos - 4);
position(newPos);
return this;
}