Details
-
Type:
Bug
-
Status: Closed
-
Priority:
P3
-
Resolution: Duplicate
-
Affects Version/s: 1.1.4
-
Fix Version/s: None
-
Component/s: core-libs
-
Subcomponent:
-
CPU:sparc
-
OS:solaris_2.5
Description
Name: dfC67450 Date: 01/15/98
The java.text.SimlpeDateFormat.parse(String, ParsePosition) incorrectly sets
ParsePosition index when String parameter contains incorrectly formatted date.
Javadoc says about java.text.DateFormat.parse(String text, ParsePosition pos) method:
* @param pos On input, the position at which to start parsing; on
* output, the position at which parsing terminated, or the
* start position if the parse failed.
Here is the test demonstrating the bug:
-----------------Test.java------------------------
import java.text.*;
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 + "\"");
// works correctly
ParsePosition pp = new ParsePosition(0);
String text = "time 10:30";
sdf.parse(text, pp);
System.out.println(" text: \"" + text + "\"");
System.out.println(" index: " + pp.getIndex());
// works correctly
pp = new ParsePosition(0);
text = "time 10:x";
sdf.parse(text, pp);
System.out.println(" text: \"" + text + "\"");
System.out.println(" index: " + pp.getIndex());
// works wrong
pp = new ParsePosition(0);
text = "time 10x";
sdf.parse(text, pp);
System.out.println(" text: \"" + text + "\"");
System.out.println(" index: " + pp.getIndex());
}
}
---------Output from the test---------------------
pattern: "'time' hh:mm"
text: "time 10:30"
index: 10
text: "time 10:x"
index: 8
text: "time 10x"
index: 0
------------------------------------------------
======================================================================
Attachments
Issue Links
- duplicates
-
JDK-4106662 java.text.DecimalFormat.parse returns 0 if string parameter is incorrect.
-
- Closed
-