Index: modules/text/src/main/java/java/text/SimpleDateFormat.java =================================================================== --- modules/text/src/main/java/java/text/SimpleDateFormat.java.orig 2006-05-24 09:24:32.000000000 +0100 +++ modules/text/src/main/java/java/text/SimpleDateFormat.java 2006-05-24 16:11:45.000000000 +0100 @@ -838,13 +838,21 @@ } private Number parseNumber(int max, String string, ParsePosition position) { - if (max == 0) - return numberFormat.parse(string, position); int digit, length = string.length(), result = 0; int index = position.getIndex(); if (max > 0 && max < length - index) length = index + max; while (index < length + && (string.charAt(index) == ' ' || + string.charAt(index) == '\t')) { + index++; + } + if (max == 0) { + position.setIndex(index); + return numberFormat.parse(string, position); + } + + while (index < length && (digit = Character.digit(string.charAt(index), 10)) != -1) { index++; result = result * 10 + digit; Index: modules/text/src/test/java/org/apache/harmony/text/tests/java/text/SimpleDateFormatTest.java =================================================================== --- modules/text/src/test/java/org/apache/harmony/text/tests/java/text/SimpleDateFormatTest.java.orig 2006-05-24 09:24:37.000000000 +0100 +++ modules/text/src/test/java/org/apache/harmony/text/tests/java/text/SimpleDateFormatTest.java 2006-05-24 17:17:24.000000000 +0100 @@ -848,6 +848,63 @@ } /** + * @tests java.text.SimpleDateFormat#parse(java.lang.String, + * java.text.ParsePosition) + */ + public void test_parse_with_spaces() { + // Regression for HARMONY-502 + SimpleDateFormat df = new SimpleDateFormat("HH:mm:ss"); + df.setLenient(false); + + char allowed_chars[] = { 0x9, 0x20 }; + String allowed_char_names[] = { "tab", "space" }; + for (int i = 0; i < allowed_chars.length ; i++) { + Date expected = + new GregorianCalendar(1970, Calendar.JANUARY, 1, 9, 7, 6).getTime(); + ParsePosition pp = new ParsePosition(0); + Date d = df.parse(allowed_chars[i]+"9:07:06", pp); + assertNotNull("hour may be prefixed by "+allowed_char_names[i], d); + assertEquals(expected, d); + + pp = new ParsePosition(0); + d = df.parse("09:"+allowed_chars[i]+"7:06", pp); + assertNotNull("minute may be prefixed by "+allowed_char_names[i], + d); + assertEquals(expected, d); + + pp = new ParsePosition(0); + d = df.parse("09:07:"+allowed_chars[i]+"6", pp); + assertNotNull("second may be prefixed by "+allowed_char_names[i], + d); + assertEquals(expected, d); + } + + char not_allowed_chars[] = { + // whitespace + 0x1c, 0x1d, 0x1e, 0x1f, 0xa, 0xb, 0xc, 0xd, + 0x2001, 0x2002, 0x2003, 0x2004, 0x2005, 0x2006, + 0x2008, 0x2009, 0x200a, 0x200b, 0x2028, 0x2029, + 0x3000, + // non-breaking space + 0xA0, 0x2007, 0x202F + }; + for (int i = 0; i < not_allowed_chars.length ; i++) { + + ParsePosition pp = new ParsePosition(0); + Date d = df.parse(not_allowed_chars[i]+"9:07", pp); + assertNull(d); + + pp = new ParsePosition(0); + d = df.parse("09:"+not_allowed_chars[i]+"7", pp); + assertNull(d); + + pp = new ParsePosition(0); + d = df.parse("09:07:"+not_allowed_chars[i]+"6", pp); + assertNull(d); + } + } + + /** * Sets up the fixture, for example, open a network connection. This method * is called before a test is executed. */