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

Serialization of java.sql.Timestamp has compatibility problem

    XMLWordPrintable

    Details

    • Subcomponent:
    • CPU:
      generic, sparc
    • OS:
      generic, solaris_2.6

      Description



      Name: ooR10001 Date: 07/05/2000


      Overloading getTime() method in java.sql.Timestamp class in jdk 1.4 causes
      compatibility problem in serialization because writeObject() method in
      base class java.util.Date use method getTime() when putting data into a
      stream.

      In jdk older then 1.4 method getTime is invoked from a superclass of Timestamp,
      in jdk 1.4 overloaded method getTime() is invoked and returned value differs
      from older jdks.

      Due to that, a stream for superclass in jdk1.4 is different from the
      corresponding stream in older jdks - it is a compatibility problem. This change
      was not approved by the CCC.

      getTime() method in jdk 1.4:

      public long getTime() {
          long time = super.getTime();
          return (time + (nanos / 1000000));
      }
      ------------------------------------------

      test example to reproduce a bug:

      import java.sql.Timestamp;

      class T extends Timestamp {

          T(long t) {
              super(t);
          }

          public long getSuperTime() {
              return getTime() - getNanos() / 1000000;
          }
      }

      public class t {

        public static void main(String[] args) {
            T stamp = new T(123L);
            if (stamp.getTime() == stamp.getSuperTime()) {
                System.out.println("Test PASSED");
            } else {
                System.out.println("Test FAILED");
            }
        }
      }
      ---------------------------------
      Test output:

      Test FAILED
      ----------------------------------
      ======================================================================

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              jellissunw Jon Ellis (Inactive)
              Reporter:
              oovsunw Oov Oov (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: