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

java.sql.Timestamp is incorrectly deserialized

XMLWordPrintable

    • 1.2fcs
    • sparc
    • solaris_2.5
    • Verified



      Name: avC70361 Date: 05/14/98



        The java.sql.Timestamp is incorrectly deserialized in
      jdk1.2-beta4 when have been serialized in jdk1.1.6. The exception
      java.io.InvalidClassException is thrown

      Here is the test demonstarating the bug.
      --------------TimestampTest.java--------
      import java.sql.Timestamp;
      import java.io.*;

      public class TimestampTest {

        public static void main(String args[]) {

          Timestamp timestamp = new Timestamp(0L);

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

            ObjectOutputStream stream = null;

            try {

              stream = new ObjectOutputStream(new FileOutputStream(args[1]));
              stream.writeObject(timestamp);
              stream.close();

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

            System.out.println(args[1] + " written successfully");

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

            ObjectInputStream stream = null;

            try {

              stream = new ObjectInputStream(new FileInputStream(args[1]));
              timestamp = (Timestamp)stream.readObject();

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

            System.out.println("Passed");

          }

          System.exit(0);

        }

      }
      -------------The test output-----------
      Under jdk1.1.6:
      <avv@stardust(pts/24).312> java -fullversion
      java full version "JDK1.1.6N"
      <avv@stardust(pts/24).313> java TimestampTest write file.ser
      file.ser written successfully
      <avv@stardust(pts/24).314> java TimestampTest read file.ser
      Passed

      Under jdk1.2beta4:
      <avv@stardust(pts/2).570> java -fullversion
      java full version "JDK-1.2beta4-E"
      <avv@stardust(pts/2).571> java TimestampTest read file.ser
      Failed:java.io.InvalidClassException: java.sql.Timestamp; Local class not compatible: stream classdesc serialVersionUID=2745179027874758501 local class serialVersionUID=9006693602311240427

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

            swhitesunw Seth White (Inactive)
            ovlasov Oleksandr Vlasov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: