[ 
https://issues.apache.org/jira/browse/DIRMINA-923?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Emmanuel Lecharny resolved DIRMINA-923.
---------------------------------------

    Resolution: Fixed

Sounds a decent proposal. 

I have applied the suggested modification in 
http://svn.apache.org/viewvc?rev=1418344&view=rev
                
> Many ClassNotFoundException in AbstractIoBuffer.putObject()
> -----------------------------------------------------------
>
>                 Key: DIRMINA-923
>                 URL: https://issues.apache.org/jira/browse/DIRMINA-923
>             Project: MINA
>          Issue Type: Bug
>          Components: Filter
>    Affects Versions: 2.0.7
>         Environment: Win 7, Java 7, MINA jars wrapped in NetBeans module.
>            Reporter: Jörg Michelberger
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> 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)) { 
> // NON-Serializable class
>                                 write(0);
>                                 super.writeClassDescriptor(desc);
>                             } 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) {
>             throw new BufferDataException(e);
>         }
>         // Fill the length field
>         int newPos = position();
>         position(oldPos);
>         putInt(newPos - oldPos - 4);
>         position(newPos);
>         return this;
>     }

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to