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

Jörg Michelberger updated DIRMINA-990:
--------------------------------------
    Description: 
There is control flow over exceptional path in 
ObjectOutputStream.writeClassDescriptor() method used in 
AbstractIoBuffer.putObject, so that serialization of primitive types is done 
via exception path. As an other point, serialization of array types is done via 
asking the classloader with a ClassForName call. Both could be a performance 
issue. I append the original source and a possible fix for this issue, which 
hopefully hits all cases the inventor of the original code wants to hit. Is it 
possible to get this in the upcomming 2.0.9 release of MINA?

Original code:
{code}
                protected void writeClassDescriptor(ObjectStreamClass desc) 
throws IOException {
                    try {
                        Class<?> clz = Class.forName(desc.getName());
                        if (!Serializable.class.isAssignableFrom(clz)) { // 
NON-Serializable class
                            write(0);
                            super.writeClassDescriptor(desc);
                        } else { // Serializable class
                            write(1);
                            writeUTF(desc.getName());
                        }
                    } catch (ClassNotFoundException ex) { // Primitive types
                        write(0);
                        super.writeClassDescriptor(desc);
                    }
                }
{code}

Possible fix
{code}
                protected void writeClassDescriptor(ObjectStreamClass desc) 
throws IOException {
                    if (desc.forClass().isArray() || 
desc.forClass().isPrimitive() || 
!Serializable.class.isAssignableFrom(desc.forClass())) {
                        write(0);
                        super.writeClassDescriptor(desc);                       
     
                    } else {
                        // Serializable class
                        write(1);
                        writeUTF(desc.getName());                            
                    }
                }
{code}

  was:
There is control flow over exceptional path in 
ObjectOutputStream.writeClassDescriptor() method used in 
AbstractIoBuffer.putObject, so that serialization of primitive types is done 
via exception path. As an other point, serialization of array types is done via 
asking the classloader with a ClassForName call. Both could be a performance 
issue. I append the original sourcce and a possible fix for this issue, which 
hopefully hits all cases the inventor of the original code wants to hit. Is it 
possible to get this in the upcomming 2.0.9 release of MINA?

Original code:
{code}
                protected void writeClassDescriptor(ObjectStreamClass desc) 
throws IOException {
                    try {
                        Class<?> clz = Class.forName(desc.getName());
                        if (!Serializable.class.isAssignableFrom(clz)) { // 
NON-Serializable class
                            write(0);
                            super.writeClassDescriptor(desc);
                        } else { // Serializable class
                            write(1);
                            writeUTF(desc.getName());
                        }
                    } catch (ClassNotFoundException ex) { // Primitive types
                        write(0);
                        super.writeClassDescriptor(desc);
                    }
                }
{code}

Possible fix
{code}
                protected void writeClassDescriptor(ObjectStreamClass desc) 
throws IOException {
                    if (desc.forClass().isArray() || 
desc.forClass().isPrimitive() || 
!Serializable.class.isAssignableFrom(desc.forClass())) {
                        write(0);
                        super.writeClassDescriptor(desc);                       
     
                    } else {
                        // Serializable class
                        write(1);
                        writeUTF(desc.getName());                            
                    }
                }
{code}


> Control flow over exceptional path in AbstractIoBuffer
> ------------------------------------------------------
>
>                 Key: DIRMINA-990
>                 URL: https://issues.apache.org/jira/browse/DIRMINA-990
>             Project: MINA
>          Issue Type: Improvement
>          Components: Core
>    Affects Versions: 2.0.8
>            Reporter: Jörg Michelberger
>              Labels: patch, performance
>
> There is control flow over exceptional path in 
> ObjectOutputStream.writeClassDescriptor() method used in 
> AbstractIoBuffer.putObject, so that serialization of primitive types is done 
> via exception path. As an other point, serialization of array types is done 
> via asking the classloader with a ClassForName call. Both could be a 
> performance issue. I append the original source and a possible fix for this 
> issue, which hopefully hits all cases the inventor of the original code wants 
> to hit. Is it possible to get this in the upcomming 2.0.9 release of MINA?
> Original code:
> {code}
>                 protected void writeClassDescriptor(ObjectStreamClass desc) 
> throws IOException {
>                     try {
>                         Class<?> clz = Class.forName(desc.getName());
>                         if (!Serializable.class.isAssignableFrom(clz)) { // 
> NON-Serializable class
>                             write(0);
>                             super.writeClassDescriptor(desc);
>                         } else { // Serializable class
>                             write(1);
>                             writeUTF(desc.getName());
>                         }
>                     } catch (ClassNotFoundException ex) { // Primitive types
>                         write(0);
>                         super.writeClassDescriptor(desc);
>                     }
>                 }
> {code}
> Possible fix
> {code}
>                 protected void writeClassDescriptor(ObjectStreamClass desc) 
> throws IOException {
>                     if (desc.forClass().isArray() || 
> desc.forClass().isPrimitive() || 
> !Serializable.class.isAssignableFrom(desc.forClass())) {
>                         write(0);
>                         super.writeClassDescriptor(desc);                     
>        
>                     } else {
>                         // Serializable class
>                         write(1);
>                         writeUTF(desc.getName());                            
>                     }
>                 }
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to