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

SimpleDateFormat.format() mishandles larger negative times

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P5
    • Resolution: Not an Issue
    • Affects Version/s: 1.3.0
    • Fix Version/s: None
    • Component/s: core-libs
    • Labels:
      None
    • Subcomponent:
    • CPU:
      sparc
    • OS:
      solaris_2.6

      Description

      The following code shows that when negative time values get large, Date.toString() starts reporting (at least) the years incorrectly. Since Date.toString() is written using SimpleDateFormat(), I presume the bug is there.

      class t {
          public static void main(String[] args) {
              for (long val = -1; val < 0; val *= 2) {
                  System.out.println("0x" + Long.toHexString(val) + ": " +
                      val + ":\t" + new java.util.Date(val));
              }
          }
      }

      Given the output below, it clearly starts to fail at time 0xffff000000000000 when the year goes BC. It looks (to me) like the sign is just not being put into the year output, but that's just a guess.

      0xffffffffffffffff: -1: Wed Dec 31 18:59:59 EST 1969
      0xfffffffffffffffe: -2: Wed Dec 31 18:59:59 EST 1969
      0xfffffffffffffffc: -4: Wed Dec 31 18:59:59 EST 1969
      0xfffffffffffffff8: -8: Wed Dec 31 18:59:59 EST 1969
      0xfffffffffffffff0: -16: Wed Dec 31 18:59:59 EST 1969
      0xffffffffffffffe0: -32: Wed Dec 31 18:59:59 EST 1969
      0xffffffffffffffc0: -64: Wed Dec 31 18:59:59 EST 1969
      0xffffffffffffff80: -128: Wed Dec 31 18:59:59 EST 1969
      0xffffffffffffff00: -256: Wed Dec 31 18:59:59 EST 1969
      0xfffffffffffffe00: -512: Wed Dec 31 18:59:59 EST 1969
      0xfffffffffffffc00: -1024: Wed Dec 31 18:59:58 EST 1969
      0xfffffffffffff800: -2048: Wed Dec 31 18:59:57 EST 1969
      0xfffffffffffff000: -4096: Wed Dec 31 18:59:55 EST 1969
      0xffffffffffffe000: -8192: Wed Dec 31 18:59:51 EST 1969
      0xffffffffffffc000: -16384: Wed Dec 31 18:59:43 EST 1969
      0xffffffffffff8000: -32768: Wed Dec 31 18:59:27 EST 1969
      0xffffffffffff0000: -65536: Wed Dec 31 18:58:54 EST 1969
      0xfffffffffffe0000: -131072: Wed Dec 31 18:57:48 EST 1969
      0xfffffffffffc0000: -262144: Wed Dec 31 18:55:37 EST 1969
      0xfffffffffff80000: -524288: Wed Dec 31 18:51:15 EST 1969
      0xfffffffffff00000: -1048576: Wed Dec 31 18:42:31 EST 1969
      0xffffffffffe00000: -2097152: Wed Dec 31 18:25:02 EST 1969
      0xffffffffffc00000: -4194304: Wed Dec 31 17:50:05 EST 1969
      0xffffffffff800000: -8388608: Wed Dec 31 16:40:11 EST 1969
      0xffffffffff000000: -16777216: Wed Dec 31 14:20:22 EST 1969
      0xfffffffffe000000: -33554432: Wed Dec 31 09:40:45 EST 1969
      0xfffffffffc000000: -67108864: Wed Dec 31 00:21:31 EST 1969
      0xfffffffff8000000: -134217728: Tue Dec 30 05:43:02 EST 1969
      0xfffffffff0000000: -268435456: Sun Dec 28 16:26:04 EST 1969
      0xffffffffe0000000: -536870912: Thu Dec 25 13:52:09 EST 1969
      0xffffffffc0000000: -1073741824: Fri Dec 19 08:44:18 EST 1969
      0xffffffff80000000: -2147483648: Sat Dec 06 22:28:36 EST 1969
      0xffffffff00000000: -4294967296: Wed Nov 12 01:57:12 EST 1969
      0xfffffffe00000000: -8589934592: Tue Sep 23 09:54:25 EDT 1969
      0xfffffffc00000000: -17179869184: Sun Jun 15 23:48:50 EDT 1969
      0xfffffff800000000: -34359738368: Fri Nov 29 02:37:41 EST 1968
      0xfffffff000000000: -68719476736: Sat Oct 28 11:15:23 EDT 1967
      0xffffffe000000000: -137438953472: Tue Aug 24 02:30:46 EDT 1965
      0xffffffc000000000: -274877906944: Sun Apr 16 09:01:33 EDT 1961
      0xffffff8000000000: -549755813888: Wed Jul 30 22:03:06 EDT 1952
      0xffffff0000000000: -1099511627776: Wed Feb 27 23:06:12 EST 1935
      0xfffffe0000000000: -2199023255552: Thu Apr 26 04:12:24 EDT 1900
      0xfffffc0000000000: -4398046511104: Thu Aug 19 12:24:48 EDT 1830
      0xfffff80000000000: -8796093022208: Fri Apr 06 04:49:37 EDT 1691
      0xfffff00000000000: -17592186044416: Sat Jul 02 13:39:15 EDT 1412
      0xffffe00000000000: -35184372088832: Tue Jan 15 06:18:31 EST 0855
      0xffffc00000000000: -70368744177664: Sun Feb 11 17:37:02 EST 0261
      0xffff800000000000: -140737488355328: Thu Apr 06 16:14:04 EST 2491
      0xffff000000000000: -281474976710656: Fri Jul 24 13:28:09 EST 6951
      0xfffe000000000000: -562949953421312: Sun Feb 27 07:56:18 EST 15870
      0xfffc000000000000: -1125899906842624: Wed May 07 20:52:37 EST 33709
      0xfff8000000000000: -2251799813685248: Wed Sep 25 22:45:14 EST 69387
      0xfff0000000000000: -4503599627370496: Thu Jul 04 02:30:29 EST 140742
      0xffe0000000000000: -9007199254740992: Thu Jan 16 10:00:59 EST 283452
      0xffc0000000000000: -18014398509481984: Fri Feb 15 01:01:58 EST 568873
      0xff80000000000000: -36028797018963968: Sat Apr 13 07:03:56 EST 1139715
      0xff00000000000000: -72057594037927936: Mon Aug 06 19:07:52 EST 2281399
      0xfe00000000000000: -144115188075855872: Sat Mar 25 19:15:44 EST 4564766
      0xfc00000000000000: -288230376151711744: Tue Jun 29 19:31:28 EST 9131501
      0xf800000000000000: -576460752303423488: Mon Jan 09 20:02:56 EST 18264970
      0xf000000000000000: -1152921504606846976: Sat Jan 31 21:05:53 EST 36531909
      0xe000000000000000: -2305843009213693952: Tue Mar 15 23:11:46 EST 73065787
      0xc000000000000000: -4611686018427387904: Tue Jun 11 03:23:32 EST 146133543
      0x8000000000000000: -9223372036854775808: Sun Dec 02 16:47:04 EST 292269055

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                okutsu Masayoshi Okutsu
                Reporter:
                karnoldsunw Kenneth Arnold (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: