United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-6295722 : Under heavy load, format will throw an ArrayIndexOutOfBoundsException

Details
Type:
Bug
Submit Date:
2005-07-12
Status:
Closed
Updated Date:
2011-02-16
Project Name:
JDK
Resolved Date:
2005-08-10
Component:
core-libs
OS:
windows_2000
Sub-Component:
java.text
CPU:
x86
Priority:
P4
Resolution:
Cannot Reproduce
Affected Versions:
5.0
Fixed Versions:

Related Reports
Relates:

Sub Tasks

Description
FULL PRODUCT VERSION :
Java 1.5.0_3

ADDITIONAL OS VERSION INFORMATION :
Windows 2000 Server, Latest service packs/Window's Updates.

A DESCRIPTION OF THE PROBLEM :
The following code is executed perhaps a half-a-million times a day, but when the load on the server is heavy (say 15x / second), it occasionally bumps with an exception:

public static String getRFC822Date(Date d) {
  SimpleDateFormat df = new SimpleDateFormat("EE, dd MMM yyyy HH:mm:ss zz");
  String s = "";
  try {
    df.setTimeZone(TimeZone.getTimeZone("GMT"));
    s = RFC822DateFormat.format(d);
  }
  catch (Exception e) {
    System.err.println("getRFC822Date(" + d + ") failed. " + e);
  }
  return s;
}

Exception examples:

17/Jun/2005:16:01:36 -0500 getRFC822Date(Fri Jun 17 16:01:36 CDT 2005) failed. java.lang.ArrayIndexOutOfBoundsException: -2147483648
20/Jun/2005:17:45:03 -0500 getRFC822Date(Mon Jun 20 17:45:03 CDT 2005) failed. java.lang.ArrayIndexOutOfBoundsException: -2147483648
21/Jun/2005:09:29:43 -0500 getRFC822Date(Tue Jun 21 09:29:43 CDT 2005) failed. java.lang.ArrayIndexOutOfBoundsException: -2147483648
22/Jun/2005:07:57:49 -0500 getRFC822Date(Wed Jun 22 07:57:49 CDT 2005) failed. java.lang.ArrayIndexOutOfBoundsException: -2147483648
22/Jun/2005:09:25:34 -0500 getRFC822Date(Wed Jun 22 09:25:34 CDT 2005) failed. java.lang.ArrayIndexOutOfBoundsException: -2147483648


A related case seems to be the lastModified() call in java.io.File.

Again, this doesn't happen on every pass. The server can handle an average load of about 5 calls / second, but I start see this error pop up about twice a day, at peak usage, which perhaps exceeds 15 calls / second.




STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run above code under heavy load.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
No exception
ACTUAL -
Every now and then, the exception is thrown.

ERROR MESSAGES/STACK TRACES THAT OCCUR :
See above.

17/Jun/2005:16:01:36 -0500 getRFC822Date(Fri Jun 17 16:01:36 CDT 2005) failed. java.lang.ArrayIndexOutOfBoundsException: -2147483648

REPRODUCIBILITY :
This bug can be reproduced occasionally.

---------- BEGIN SOURCE ----------
public static String getRFC822Date(Date d) {
  SimpleDateFormat df = new SimpleDateFormat("EE, dd MMM yyyy HH:mm:ss zz");
  String s = "";
  try {
    df.setTimeZone(TimeZone.getTimeZone("GMT"));
    s = RFC822DateFormat.format(d);
  }
  catch (Exception e) {
    System.err.println("getRFC822Date(" + d + ") failed. " + e);
  }
  return s;
}

---------- END SOURCE ----------
###@###.### 2005-07-12 09:56:52 GMT

                                    

Comments
EVALUATION

The symptom isn't reproducible with the following test program on a 4-processor system for 100 hours.

----
import java.util.*;
import java.text.*;
 
public class SDFThreadTest {
    static volatile boolean runrun = true;
 
    public static void main(String[] args) {
        long millis = System.currentTimeMillis() + (Integer.parseInt(args[0]) * 3600000L);
        System.out.println("job will end at " + new Date(millis));
        Thread[] t = new Thread[4];
        for (int i = 0; i < t.length; i++) {
            t[i] = new Thread(new Work(i));
            t[i].start();
        }
 
        while (millis > System.currentTimeMillis()) {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {}
        }
        runrun = false;
        for (int i = 0; i < t.length; i++) {
            try {
                t[i].join();
            } catch (Exception e) {
            }
        }
    }
 
    public static String getRFC822Date(Date d) {
      SimpleDateFormat df = new SimpleDateFormat("EE, dd MMM yyyy HH:mm:ss zz");
      String s = "";
      try {
        df.setTimeZone(TimeZone.getTimeZone("GMT"));
        s = df.format(d);
      } catch (Exception e) {
        throw new RuntimeException("getRFC822Date(" + d + ") failed. ", e);
      }
      return s;
    }
 
    static class Work implements Runnable {
        final Date date;
        final String expected;
 
        Work(int x) {
            date = new Date(System.currentTimeMillis() + x * 24 * 3600000);
            expected = SDFThreadTest.getRFC822Date(date);
        }
 
        public void run() {
           while (runrun) {
                String s = getRFC822Date(date);
                if (!s.equals(expected)) {
                    runrun = false;
                    throw new RuntimeException("got " + s + ", expected " + expected);
                }
            }
        }
    }
}
----

Closing this CR as not reproducible. Please reopen if it's reproducible with a concrete test case.

Please note that SimpleDateFormat.format() isn't thread-safe due to the embedded Calendar instance. It is necessary to synchronize a SimpleDateFormat to format or parse a date.
                                     
2005-08-10
EVALUATION

We'd appreciate it if the submitter can provide its stack trace.
###@###.### 2005-07-12 14:19:52 GMT
                                     
2005-07-12



Hardware and Software, Engineered to Work Together