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

DecimalFormat cannot be deserialized in 1.3.1 when serialized with Java 6

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3 P3
    • None
    • 6
    • core-libs
    • x86
    • windows_xp

      FULL PRODUCT VERSION :
      java version "1.6.0"
      Java(TM) SE Runtime Environment (build 1.6.0-b105)
      Java HotSpot(TM) Client VM (build 1.6.0-b105, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows XP [Version 5.1.2600]

      A DESCRIPTION OF THE PROBLEM :
      JRE 1.3.1 throws the following exception when deserializing a DecimalFormat instance serialized by JRE 1.6.0. This does not occur for instances serialized by JRE 1.5.0.

      java.io.StreamCorruptedException: Type code out of range, is 126
      at java.io.ObjectInputStream.peekCode(ObjectInputStream.java:1551)
      at java.io.ObjectInputStream.readObject(ObjectInputStream.java:287)
      at java.io.ObjectInputStream.inputClassFields(ObjectInputStream.java:2258)
      at java.io.ObjectInputStream.defaultReadObject(ObjectInputStream.java:514)
      at java.text.DecimalFormat.readObject(DecimalFormat.java:2017)
      at java.lang.reflect.Method.invoke(Native Method)
      at java.io.ObjectInputStream.invokeObjectReader(ObjectInputStream.java:2209)
      at java.io.ObjectInputStream.inputObject(ObjectInputStream.java:1406)
      at java.io.ObjectInputStream.readObject(ObjectInputStream.java:381)
      at java.io.ObjectInputStream.readObject(ObjectInputStream.java:231)

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Compile the following classes.
      2. Run SerializeTest using JRE 1.6.0
      3. Run DeserializeTest using 1.3.1

      -----------------------------------------------------------------------
      import java.io.FileOutputStream;
      import java.io.ObjectOutputStream;
      import java.text.DecimalFormat;

      public class SerializeTest {
      public static void main(String[] args) throws Exception {
      ObjectOutputStream out = new ObjectOutputStream(
      new FileOutputStream("DecimalFormatSerialized"));
      out.writeObject(new DecimalFormat("#,###"));
      out.close();
      }
      }

      -----------------------------------------------------------------------
      import java.io.FileInputStream;
      import java.io.ObjectInputStream;

      public class DeserializeTest {
      public static void main(String[] args) throws Exception {
      ObjectInputStream in = new ObjectInputStream(
      new FileInputStream("DecimalFormatSerialized"));
      in.readObject();
      in.close();
      }
      }


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Excpected DecimalFormat to be deserialized correctly.
      ACTUAL -
      DeserializeTest, when run using JRE 1.3.1, throws the exception above.

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      See above

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      See above
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Don't serialize DecimalFormat. Instead, serialize a format pattern and recreate the DecimalFormat instance when needed.

      Release Regression From : 5
      The above release value was the last known release where this
      bug was not reproducible. Since then there has been a regression.

            peytoia Yuka Kamiya (Inactive)
            ryeung Roger Yeung (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: