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

java.math.BigDecimal of jdk1.2 not compatible with the one of jdk1.1.4

XMLWordPrintable

    • sparc
    • solaris_2.5



      Name: mgC56079 Date: 10/13/97



        The java.math.BigDecimal class serialized on jdk1.1.4 platform fails to be
      deserialized on jdk1.2 platform due to the incompatibility of the class on
      jdk1.1.4 and jdk1.2 platforms.

        Here is the test demonstraiting the bug:
      ----------BigDecimalTest.java----------------
      import java.io.*;
      import java.math.BigDecimal;

      public class BigDecimalTest {

        public static void main(String args[]) {

          BigDecimal bigDecimal;

          String filepath = "BigDecimal.ser";

          if (args[0].equals("write")) {

            bigDecimal = new BigDecimal("0");

            ObjectOutputStream stream = null;

            try {

              stream = new ObjectOutputStream(new FileOutputStream(filepath));
              stream.writeObject(bigDecimal);
              stream.close();

            } catch(IOException e) {
              System.out.println("Couldn't write to " + filepath + " : " + e);
              System.exit(1);
            }

            System.out.println("BigDecimal written successfully");

          } else if (args[0].equals("read")) {

            ObjectInputStream stream = null;

            try {

              stream = new ObjectInputStream(new FileInputStream(filepath));
              bigDecimal = (BigDecimal)stream.readObject();

            } catch(InvalidClassException e) {
              System.out.println("Failed:" + e);
              System.exit(1);
            } catch(Exception e) {
              System.out.println(
                "Failed: couldn't read from" + filepath + " : " + e
              );
              System.exit(1);
            }

            System.out.println("Passed");

          }

          System.exit(0);

        }

      }

      ----------The test output on jdk1.1.4-----------
      #>java BigDecimalTest write
      BigDecimal written successfully
      #>java BigDecimalTest read
      Passed
      ----------The test output on jdk1.2-------------
      #>java BigDecimalTest read
      Failed:java.io.InvalidClassException: java.math.BigDecimal; Local class not compatible


      ======================================================================

            jjb Josh Bloch
            mgorshen Mikhail Gorshenev (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: