JDK-4460757 : SimpleDateFormat.parse throws StringIndexOutOfBoundsException
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.text
  • Affected Version: 1.3.0
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic
  • CPU: generic
  • Submitted: 2001-05-18
  • Updated: 2001-05-24
  • Resolved: 2001-05-24
Related Reports
Duplicate :  
Description

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) 
======================================================================

Comments
WORK AROUND Name: bsC130419 Date: 05/18/2001 If exception is thrown ignore timezone and use pattern "EEE, dd MMM yy HH:mm:ss" instead. ======================================================================
11-06-2004

EVALUATION The same issue as 4212077. masayoshi.okutsu@Eng 2001-05-24
24-05-2001