-
Bug
-
Resolution: Cannot Reproduce
-
P3
-
None
-
1.1.4
-
sparc
-
solaris_2.5
Name: dfC67450 Date: 01/16/98
The java.text.SimlpeDateFormat.parse(String, ParsePosition) throws unexpected
StringIndexOutOfBoundsException when String parameter contains incorrectly
formatted date.
Javadoc says about java.text.DateFormat.parse(String text, ParsePosition pos) method:
*
* @return A Date, or null if the input could not be parsed
*
Here is the test demonstrating the bug:
-----------------Test.java------------------------
import java.text.*;
import java.util.*;
public class Test {
public static void main (String args[]){
SimpleDateFormat sdf = new SimpleDateFormat();
String pattern = "'time' hh:mm";
sdf.applyPattern(pattern);
System.out.println("pattern: \"" + pattern + "\"");
System.out.println();
// works correctly
ParsePosition pp = new ParsePosition(0);
String text = "time ";
System.out.println(" text: \"" + text + "\"");
Date date = sdf.parse(text, pp);
System.out.println(" date: " + date);
System.out.println();
// works wrong
pp = new ParsePosition(0);
text = "time";
System.out.println(" text: \"" + text + "\"");
date = sdf.parse(text, pp);
System.out.println(" date: " + date);
}
}
---------Output from the test---------------------
pattern: "'time' hh:mm"
text: "time "
date: null
text: "time"
java.lang.StringIndexOutOfBoundsException: String index out of range: 4
at java.lang.String.charAt(String.java)
at java.text.SimpleDateFormat.parse(SimpleDateFormat.java)
at Test.main(Test.java:23)
------------------------------------------------
======================================================================