Uploaded image for project: 'Harmony'
  1. Harmony
  2. HARMONY-4996

[classlib][luni] Incorrect deserialization of Externalizable classes

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 5.0M4
    • None
    • Win XP
    • Moderate

    Description

      The testcase below passed on RI but failed on Harmony with the following stacktrace:
      java.io.StreamCorruptedException: Wrong format: 0x0
      at java.io.ObjectInputStream.readNonPrimitiveContent(ObjectInputStream.java:842)
      at java.io.ObjectInputStream.readObject(ObjectInputStream.java:2128)
      at java.io.ObjectInputStream.readObject(ObjectInputStream.java:283)
      at Test.main(Test.java:18)

      --------------------------- Test.java --------------------------------
      import java.io.*;

      public class Test {
      static ObjectStreamClass[] objs = new ObjectStreamClass[1000];
      static int pos = 0;

      public static void main(String[] args) {
      try

      { PipedOutputStream pout = new PipedOutputStream(); PipedInputStream pin = new PipedInputStream(pout); ObjectOutputStream oout = new TestObjectOutputStream(pout); oout.writeObject(new TestExtObject()); oout.writeObject("test"); oout.close(); pos = 0; ObjectInputStream oin = new TestObjectInputStream(pin); oin.readObject(); oin.readObject(); System.out.println("Done."); }

      catch (Exception ex)

      { ex.printStackTrace(); }

      }

      public static class TestExtObject implements Externalizable {
      public void writeExternal(ObjectOutput out) throws IOException

      { out.writeInt(10); }

      public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException

      { in.readInt(); }

      }

      static class TestObjectOutputStream extends ObjectOutputStream {
      public TestObjectOutputStream(OutputStream out) throws IOException

      { super(out); }

      protected void writeClassDescriptor(ObjectStreamClass osc) throws IOException

      { objs[pos++] = osc; }

      }

      static class TestObjectInputStream extends ObjectInputStream {
      public TestObjectInputStream(InputStream in) throws IOException

      { super(in); }

      protected ObjectStreamClass readClassDescriptor() throws IOException, ClassNotFoundException

      { return (ObjectStreamClass) objs[pos++]; }

      }
      }
      -------------------------------------------------------------------------

      This test actually saves the incoming ObjectStreamClass-es in local array and does not write them to ObjectOutputStream (and takes them from this array in de-serialization). It seems like Externalizable class does not properly de-serialized as the exception occured during the next readObject() call.

      Attachments

        1. H-4996.patch
          5 kB
          Mikhail Markov

        Activity

          People

            mmarkov Mikhail Markov
            mmarkov Mikhail Markov
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: