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

Many ClassNotFoundException in AbstractIoBuffer.putObject()

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.0.7
    • Fix Version/s: None
    • Component/s: Filter
    • Labels:
      None
    • Environment:
      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))

      { // 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;
      }

        Attachments

          Activity

            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:

                Time Tracking

                Estimated:
                Original Estimate - 1h
                1h
                Remaining:
                Remaining Estimate - 1h
                1h
                Logged:
                Time Spent - Not Specified
                Not Specified