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

[Fmt-Da] Under heavy load, DateFormat format throws ArrayIndexOutOfBoundsException

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 5.0
    • core-libs
    • x86
    • windows_xp

      FULL PRODUCT VERSION :
      java version "1.5.0_04"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_04-b05)
      Java HotSpot(TM) Client VM (build 1.5.0_04-b05, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows XP [Version 5.1.2600]

      EXTRA RELEVANT SYSTEM CONFIGURATION :
      This was opened by another individual as 6295722, however, his was only intermittently reproducible and was closed by Sun as not able to reproduce.

      My test fails *every time* within a second of starting the program.

      Sun team says they tested 6295722 for 100hours on a 4CPU machine with no failure.
      My system is a 3.2Ghz HT single-CPU system. I would suggest testing on a high-mhz Intel box. (in the case the 4-cpu machine was a sparc /w a slower mhz rating or is simply a platform issue - i know it's rare, but it could be a factor)

      A DESCRIPTION OF THE PROBLEM :
      DateFormat.format fails with an ArrayIndexOutOfBoundsException under heavy load.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run test case below.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      No failures, should run continuously.
      ACTUAL -
      java.lang.ArrayIndexOutOfBoundsException: -2147483648
      at java.text.SimpleDateFormat.subFormat(SimpleDateFormat.java:934)
      at java.text.SimpleDateFormat.format(SimpleDateFormat.java:806)
      at java.text.SimpleDateFormat.format(SimpleDateFormat.java:778)
      at java.text.DateFormat.format(DateFormat.java:314)
      at test$1.run(test.java:24)

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      java.lang.ArrayIndexOutOfBoundsException: -2147483648
      at java.text.SimpleDateFormat.subFormat(SimpleDateFormat.java:934)
      at java.text.SimpleDateFormat.format(SimpleDateFormat.java:806)
      at java.text.SimpleDateFormat.format(SimpleDateFormat.java:778)
      at java.text.DateFormat.format(DateFormat.java:314)
      at test$1.run(test.java:24)

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      public class test {
          private static final DateFormat dateFormat = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss zzz");
          public static void main(String[] args) throws Exception {
              for (int c=0; c<3; c++) {
                  Thread th = new Thread() {
                      public void run() {
                          Random rand = new Random();
                          while (true) {
                              Date date = new Date(rand.nextLong());
                              try {
                                  dateFormat.format(date);
                              } catch (RuntimeException e) {
                                  e.printStackTrace();
                                  System.exit(1);
                              }
                          }
                      }
                  };
                  th.start();
              }
          }
      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Can use separate instances of DateFormat, however this is very expensive in instances and there are some places we cannot control it's use. (3rd party)
      Instance-saving options such as pooling would be unnecessarily complex.

            okutsu Masayoshi Okutsu
            okutsu Masayoshi Okutsu
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: