This is the mail archive of the
java@gcc.gnu.org
mailing list for the Java project.
Re: SimpleDateFormat parse bug: doesn't like embedded spaces
- From: Bryce McKinlay <mckinlay at redhat dot com>
- To: Scott Gilbertson <scottg at mantatest dot com>
- Cc: java at gcc dot gnu dot org
- Date: Fri, 03 Feb 2006 19:54:12 -0500
- Subject: Re: SimpleDateFormat parse bug: doesn't like embedded spaces
- References: <160c01c62910$913a4b10$3c16a8c0@mantatest.com>
Scott Gilbertson wrote:
I found a difference between SimpleDateFormat.parse in GCJ/Classpath vs.
Sun. Tiny test program attached.
The attached program runs the following strings:
"2:03:34"
"2: 3:34"
Through this SimpleDateFormat:
new SimpleDateFormat ("H':'m':'s")
The result with GCJ (from svn a Jan 24) is different from Sun JRE 1.4.2_08\
Hmm, another undocumented behaviour of Sun's class libraries. The
attached patch should make us compatible. We'll need to add a mauve test
for this, too.
Bryce
2006-02-03 Bryce McKinlay <mckinlay@redhat.com>
* java/text/SimpleDateFormat.java (parse): Ignore leading whitespace
characters in numeric fields.
Index: classpath/java/text/SimpleDateFormat.java
===================================================================
--- classpath/java/text/SimpleDateFormat.java (revision 110474)
+++ classpath/java/text/SimpleDateFormat.java (working copy)
@@ -1086,7 +1086,20 @@
numberFormat.setMaximumIntegerDigits(fmt_count);
if (maybe2DigitYear)
index = pos.getIndex();
- Number n = numberFormat.parse(dateStr, pos);
+
+ // Ignore leading whitespace, for compatibility.
+ try
+ {
+ int wsIndex = pos.getIndex();
+ while (Character.isWhitespace(dateStr.charAt(wsIndex)))
+ pos.setIndex(++wsIndex);
+ }
+ catch (StringIndexOutOfBoundsException ignored)
+ {
+ return null;
+ }
+
+ Number n = numberFormat.parse(dateStr, pos);
if (pos == null || ! (n instanceof Long))
return null;
value = n.intValue() + offset;
@@ -1177,7 +1190,7 @@
pos.setErrorIndex(pos.getIndex());
return null;
}
- }
+ }
/**
* <p>