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

java.sql.Date is incorrectly deserialized in jdk1.2beta4

    Details

    • Subcomponent:
    • CPU:
      sparc
    • OS:
      solaris_2.5

      Description



      Name: avC70361 Date: 06/15/98



        The java.sql.Date is incorrectly deserialized in jdk1.2beta4 when has been
      serialized in jdk1.1.6. The instance deserialized is not equal to the instance
      created for the same date.

      Here is a test demonstrating the bug.
      ----------SQLDateTest.java-------------
      import java.sql.Date;
      import java.io.*;

      public class SQLDateTest {

        public static void main(String args[]) {

          Date expected = new Date(123456789L);

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

            ObjectOutputStream stream = null;

            try {

              stream = new ObjectOutputStream(new FileOutputStream(args[1]));
              stream.writeObject(expected);
              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]));
              Date date = (Date)stream.readObject();

              if (!expected.equals(date)) {
                System.out.println(
                  "Deserialized date is not equal to expected\n" +
                  "deserialized date = " + date + "\n" +
                  "expected date = " + expected
                );
                System.exit(1);
              }
            } 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/3).314> java -version
      java version "1.1.6"
      <avv@stardust(pts/3).315> java SQLDateTest write file.ser
      file.ser written successfully
      <avv@stardust(pts/3).316> java SQLDateTest read file.ser
      Passed

      Under jdk1.2beta4:
      <avv@stardust(pts/3).320> java -version
      java version "1.2beta4"
      Classic VM (build JDK-1.2beta4-I, green threads, sunwjit)
      <avv@stardust(pts/3).321> java SQLDateTest read file.ser
      Deserialized date is not equal to expected
      deserialized date = 1970-01-03
      expected date = 1970-01-02

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

        Attachments

          Activity

            People

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

              Dates

              • Created:
                Updated:
                Resolved:
                Imported:
                Indexed: