Uploaded image for project: 'MINA'
  1. MINA
  2. DIRMINA-990

Control flow over exceptional path in AbstractIoBuffer

    Details

    • Type: Improvement
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.0.8
    • Fix Version/s: 2.0.9
    • Component/s: Core
    • Labels:

      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:

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

      Possible fix

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

        Activity

        Hide
        elecharny Emmanuel Lecharny added a comment -

        Will finally get it included in 2.0.9. Vote started this morning.

        Show
        elecharny Emmanuel Lecharny added a comment - Will finally get it included in 2.0.9. Vote started this morning.
        Hide
        elecharny Emmanuel Lecharny added a comment -

        Patch applied with Commit: c1792331521ec1f50e9c71228a20ca4ab21029fa

        Show
        elecharny Emmanuel Lecharny added a comment - Patch applied with Commit: c1792331521ec1f50e9c71228a20ca4ab21029fa
        Hide
        elecharny Emmanuel Lecharny added a comment -

        I have applied your suggested patch, ran tests : no problem.

        I'll commit them.

        Many thanks !

        Show
        elecharny Emmanuel Lecharny added a comment - I have applied your suggested patch, ran tests : no problem. I'll commit them. Many thanks !
        Hide
        elecharny Emmanuel Lecharny added a comment -

        Ahhh... Sadly, MINA 2.0.9 is currently being voted.

        We could get your patch included in 2.0.10, as we have some more fixes to apply soon.

        Show
        elecharny Emmanuel Lecharny added a comment - Ahhh... Sadly, MINA 2.0.9 is currently being voted. We could get your patch included in 2.0.10, as we have some more fixes to apply soon.

          People

          • Assignee:
            Unassigned
            Reporter:
            j.michelberger Jörg Michelberger
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development