Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6240271

Deserializing an object with a new field throws java.io.StreamCorruptedException

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Won't Fix
    • Icon: P3 P3
    • None
    • 6, 6u23
    • core-libs

      After serializing an object on 1.6 with the code (WriteTest.java, attached), deserializing the object with the code (ReadTest.java, also attached) on the prior releases (say 1.4.1) will throw the following exception:

      java.io.StreamCorruptedException
              at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1301)
              at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1845)
              at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1769)
              at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1646)
              at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1274)
              at java.io.ObjectInputStream.readObject(ObjectInputStream.java:324)
              at ReadTest.<init>(ReadTest.java:13)
              at ReadTest.main(ReadTest.java:6)

      According to the serialization specification, adding a field is a compatible change:
      http://java.sun.com/j2se/1.5.0/docs/guide/serialization/spec/version.html#6519

      That the new field uses a class that's not known to an old JRE, RoundingMode in this case, shouldn't matter because deserialization should just skip over the data for the unknown field.
      ###@###.### 2005-03-14 19:14:33 GMT
      ###@###.### 2005-03-14 19:16:54 GMT

            Unassigned Unassigned
            naoto Naoto Sato
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: