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

Date objects do not preserve milliseconds properly

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: na, rel-2.0, rel_3.5, solaris_10, solaris_2.4, 1.0, 1.0beta2, 2.0.0.312, 2.0alpha, 2.1.1, 2.p, 3.d, 4.1.3, 4.3, 7.4, 7.5, 7.5.1, 7.6.5, 7.6.6, 8.4, beta, 1.1
    • Fix Version/s: 1.1
    • Component/s: hotspot
    • Subcomponent:
    • Resolved In Build:
      1.1
    • CPU:
      generic, other, unknown, x86, sparc
    • OS:
      generic, solaris, solaris_1, solaris_2.3, solaris_2.4, solaris_2.5, solaris_2.5.1, solaris_2.6, solaris_8, solaris_9, solaris_10, windows_95

      Description

      The class Date fails to preserve milliseconds properly. The result
      is anomalous behavior, as exhibited by the following code:

      import java.util.Date;

      class Dsame {
        public static void main(String[] argv) {
          Date d = new Date();
          Date e = new Date(d.getTime());
          e.setYear(e.getYear());
          System.out.println(d.equals(e));
        }
      }

      This prints "false"; that is, the two Date objects are no longer equal despite the
      fact that the only modification to e was to set the year to the value it already had.

      The culprit is the native method java_util_Date_computeValue in file date.c.
      The method java_util_Date_expand correctly sets the tm_millis field of the
      Date object when converting from a long value to date/time components;
      but java_util_Date_computeValue ignores the tm_millis field when reassembling
      the date/time components to form a long value. I believe the code

      thisptr->value = ll_mul(int2ll(mktime(&tm)), int2ll(1000));

      should be something like (please check it)

      thisptr->value = ll_add(ll_mul(int2ll(mktime(&tm)), int2ll(1000)),
                              int2ll(thisptr->tm_millis));
      ---

        Attachments

          Activity

            People

            • Assignee:
              duke J. Duke (Inactive)
              Reporter:
              duke J. Duke (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Imported:
                Indexed: