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

SimpleDateFormat.parse throws StringIndexOutOfBoundsException

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.3.0
    • core-libs
    • generic
    • generic



      Name: bsC130419 Date: 05/18/2001


      D:\users\work>java -version
      java version "1.3.0_01"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0_01)
      Java HotSpot(TM) Client VM (build 1.3.0_01, mixed mode)

      This happens also with versio 1.2.2 in Solaris...


      SimpleDateFormat.parse throws an exception. It should either return null or
      parse the date.

      Following code:

      import java.util.*;
      import java.text.*; //DateFormat, ParsePosition,...

      class Tester{
        public static void main(String[] args)throws Exception{
          try{
            Date d=new SimpleDateFormat("EEE, dd MMM yy HH:mm:ss z", Locale.US).parse
      ("Fri, 09 Feb 2001 07:16:01 GMT+2",new ParsePosition(0));
        System.out.println("1: "+d);
          }catch(Exception e){
        System.out.println("1: "+e);
          }

          try{
            Date d=new SimpleDateFormat("EEE, dd MMM yy HH:mm:ss z", Locale.US).parse
      ("Fri, 09 Feb 2001 07:16:01 GMT+0200",new ParsePosition(0));
        System.out.println("2: "+d);
          }catch(Exception e){
        System.out.println("2: "+e);
          }

          try{
            Date d=new SimpleDateFormat("EEE, dd MMM yy HH:mm:ss z", Locale.US).parse
      ("Fri, 09 Feb 2001 07:16:01 GMT+02:00",new ParsePosition(0));
        System.out.println("3: "+d);
          }catch(Exception e){
        System.out.println("3: "+e);
          }
        }
      }

      Produces following result:

      D:\users\work>java -cp . Tester
      1: java.lang.StringIndexOutOfBoundsException: String index out of range: 31
      2: java.lang.StringIndexOutOfBoundsException: String index out of range: 34
      3: Fri Feb 09 07:16:01 GMT+02:00 2001
      (Review ID: 124611)
      ======================================================================

            okutsu Masayoshi Okutsu
            bstrathesunw Bill Strathearn (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: