ICU-9968 Return value of SimpleDateFormat subparse not correctly reflecting error at start pos 0
X-SVN-Rev: 33871
This commit is contained in:
parent
9333318d4e
commit
5442e5a7a4
@ -2565,7 +2565,7 @@ public class SimpleDateFormat extends DateFormat {
|
|||||||
}
|
}
|
||||||
return start + bestMatchLength;
|
return start + bestMatchLength;
|
||||||
}
|
}
|
||||||
return -start;
|
return ~start;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int regionMatchesWithOptionalDot(String text, int start, String data, int length) {
|
private int regionMatchesWithOptionalDot(String text, int start, String data, int length) {
|
||||||
@ -2696,7 +2696,7 @@ public class SimpleDateFormat extends DateFormat {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (patternCharIndex == -1) {
|
if (patternCharIndex == -1) {
|
||||||
return -start;
|
return ~start;
|
||||||
}
|
}
|
||||||
|
|
||||||
currentNumberFormat = getNumberFormat(ch);
|
currentNumberFormat = getNumberFormat(ch);
|
||||||
@ -2712,7 +2712,7 @@ public class SimpleDateFormat extends DateFormat {
|
|||||||
// of the string, then fail.
|
// of the string, then fail.
|
||||||
for (;;) {
|
for (;;) {
|
||||||
if (start >= text.length()) {
|
if (start >= text.length()) {
|
||||||
return -start;
|
return ~start;
|
||||||
}
|
}
|
||||||
int c = UTF16.charAt(text, start);
|
int c = UTF16.charAt(text, start);
|
||||||
if (!UCharacter.isUWhiteSpace(c) || !PatternProps.isWhiteSpace(c)) {
|
if (!UCharacter.isUWhiteSpace(c) || !PatternProps.isWhiteSpace(c)) {
|
||||||
@ -2755,14 +2755,14 @@ public class SimpleDateFormat extends DateFormat {
|
|||||||
if (!parsedNumericLeapMonth) {
|
if (!parsedNumericLeapMonth) {
|
||||||
if (obeyCount) {
|
if (obeyCount) {
|
||||||
if ((start+count) > text.length()) {
|
if ((start+count) > text.length()) {
|
||||||
return -start;
|
return ~start;
|
||||||
}
|
}
|
||||||
number = parseInt(text, count, pos, allowNegative,currentNumberFormat);
|
number = parseInt(text, count, pos, allowNegative,currentNumberFormat);
|
||||||
} else {
|
} else {
|
||||||
number = parseInt(text, pos, allowNegative,currentNumberFormat);
|
number = parseInt(text, pos, allowNegative,currentNumberFormat);
|
||||||
}
|
}
|
||||||
if (number == null && patternCharIndex != 30) {
|
if (number == null && patternCharIndex != 30) {
|
||||||
return -start;
|
return ~start;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2847,7 +2847,7 @@ public class SimpleDateFormat extends DateFormat {
|
|||||||
cal.set(Calendar.YEAR, value);
|
cal.set(Calendar.YEAR, value);
|
||||||
return pos.getIndex();
|
return pos.getIndex();
|
||||||
}
|
}
|
||||||
return -start;
|
return ~start;
|
||||||
case 2: // 'M' - MONTH
|
case 2: // 'M' - MONTH
|
||||||
case 26: // 'L' - STAND_ALONE_MONTH
|
case 26: // 'L' - STAND_ALONE_MONTH
|
||||||
if (count <= 2) { // i.e., M/MM, L/LL
|
if (count <= 2) { // i.e., M/MM, L/LL
|
||||||
@ -2957,7 +2957,7 @@ public class SimpleDateFormat extends DateFormat {
|
|||||||
cal.setTimeZone(tz);
|
cal.setTimeZone(tz);
|
||||||
return pos.getIndex();
|
return pos.getIndex();
|
||||||
}
|
}
|
||||||
return -start;
|
return ~start;
|
||||||
}
|
}
|
||||||
case 23: // 'Z' - TIMEZONE_RFC
|
case 23: // 'Z' - TIMEZONE_RFC
|
||||||
{
|
{
|
||||||
@ -2969,7 +2969,7 @@ public class SimpleDateFormat extends DateFormat {
|
|||||||
cal.setTimeZone(tz);
|
cal.setTimeZone(tz);
|
||||||
return pos.getIndex();
|
return pos.getIndex();
|
||||||
}
|
}
|
||||||
return -start;
|
return ~start;
|
||||||
}
|
}
|
||||||
case 24: // 'v' - TIMEZONE_GENERIC
|
case 24: // 'v' - TIMEZONE_GENERIC
|
||||||
{
|
{
|
||||||
@ -2982,7 +2982,7 @@ public class SimpleDateFormat extends DateFormat {
|
|||||||
cal.setTimeZone(tz);
|
cal.setTimeZone(tz);
|
||||||
return pos.getIndex();
|
return pos.getIndex();
|
||||||
}
|
}
|
||||||
return -start;
|
return ~start;
|
||||||
}
|
}
|
||||||
case 29: // 'V' - TIMEZONE_SPECIAL
|
case 29: // 'V' - TIMEZONE_SPECIAL
|
||||||
{
|
{
|
||||||
@ -3008,7 +3008,7 @@ public class SimpleDateFormat extends DateFormat {
|
|||||||
cal.setTimeZone(tz);
|
cal.setTimeZone(tz);
|
||||||
return pos.getIndex();
|
return pos.getIndex();
|
||||||
}
|
}
|
||||||
return -start;
|
return ~start;
|
||||||
}
|
}
|
||||||
case 31: // 'O' - TIMEZONE_LOCALIZED_GMT_OFFSET
|
case 31: // 'O' - TIMEZONE_LOCALIZED_GMT_OFFSET
|
||||||
{
|
{
|
||||||
@ -3020,7 +3020,7 @@ public class SimpleDateFormat extends DateFormat {
|
|||||||
cal.setTimeZone(tz);
|
cal.setTimeZone(tz);
|
||||||
return pos.getIndex();
|
return pos.getIndex();
|
||||||
}
|
}
|
||||||
return -start;
|
return ~start;
|
||||||
}
|
}
|
||||||
case 32: // 'X' - TIMEZONE_ISO
|
case 32: // 'X' - TIMEZONE_ISO
|
||||||
{
|
{
|
||||||
@ -3049,7 +3049,7 @@ public class SimpleDateFormat extends DateFormat {
|
|||||||
cal.setTimeZone(tz);
|
cal.setTimeZone(tz);
|
||||||
return pos.getIndex();
|
return pos.getIndex();
|
||||||
}
|
}
|
||||||
return -start;
|
return ~start;
|
||||||
}
|
}
|
||||||
case 33: // 'x' - TIMEZONE_ISO_LOCAL
|
case 33: // 'x' - TIMEZONE_ISO_LOCAL
|
||||||
{
|
{
|
||||||
@ -3078,7 +3078,7 @@ public class SimpleDateFormat extends DateFormat {
|
|||||||
cal.setTimeZone(tz);
|
cal.setTimeZone(tz);
|
||||||
return pos.getIndex();
|
return pos.getIndex();
|
||||||
}
|
}
|
||||||
return -start;
|
return ~start;
|
||||||
}
|
}
|
||||||
case 27: // 'Q' - QUARTER
|
case 27: // 'Q' - QUARTER
|
||||||
if (count <= 2) { // i.e., Q or QQ.
|
if (count <= 2) { // i.e., Q or QQ.
|
||||||
@ -3148,7 +3148,7 @@ public class SimpleDateFormat extends DateFormat {
|
|||||||
cal.set(field, number.intValue());
|
cal.set(field, number.intValue());
|
||||||
return pos.getIndex();
|
return pos.getIndex();
|
||||||
}
|
}
|
||||||
return -start;
|
return ~start;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,6 +11,7 @@ import java.io.ByteArrayOutputStream;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.ObjectInputStream;
|
import java.io.ObjectInputStream;
|
||||||
import java.io.ObjectOutputStream;
|
import java.io.ObjectOutputStream;
|
||||||
|
import java.text.ParsePosition;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
@ -2333,7 +2334,31 @@ public class CalendarRegression extends com.ibm.icu.dev.test.TestFmwk {
|
|||||||
dateBit2 = myCal.getTimeInMillis();
|
dateBit2 = myCal.getTimeInMillis();
|
||||||
assertFalse("Fail: error in setMillis, allowed invalid value : " + testMillis + "...returned dayOfMonth : " + dateBit1 + " millis : " + dateBit2, missedException);
|
assertFalse("Fail: error in setMillis, allowed invalid value : " + testMillis + "...returned dayOfMonth : " + dateBit1 + " millis : " + dateBit2, missedException);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test case for ticket 9968
|
||||||
|
* subparse fails to return an error indication when start pos is 0
|
||||||
|
*/
|
||||||
|
public void TestT9968() {
|
||||||
|
SimpleDateFormat sdf0 = new SimpleDateFormat("-MMMM");
|
||||||
|
ParsePosition pos0 = new ParsePosition(0);
|
||||||
|
Date d0 = sdf0.parse("-September", pos0);
|
||||||
|
logln("sdf0: "+pos0.getErrorIndex() + "/" + pos0.getIndex());
|
||||||
|
assertTrue("Fail: failed a good test", pos0.getErrorIndex() == -1);
|
||||||
|
|
||||||
|
SimpleDateFormat sdf1 = new SimpleDateFormat("-MMMM");
|
||||||
|
ParsePosition pos1 = new ParsePosition(0);
|
||||||
|
Date d1 = sdf1.parse("-????", pos1);
|
||||||
|
logln("sdf1: "+pos1.getErrorIndex() + "/" + pos1.getIndex());
|
||||||
|
assertTrue("Fail: failed to detect bad parse", pos1.getErrorIndex() == 1);
|
||||||
|
|
||||||
|
SimpleDateFormat sdf2 = new SimpleDateFormat("MMMM");
|
||||||
|
ParsePosition pos2 = new ParsePosition(0);
|
||||||
|
Date d2 = sdf2.parse("????", pos2);
|
||||||
|
logln("sdf2: "+pos2.getErrorIndex() + "/" + pos2.getIndex());
|
||||||
|
assertTrue("Fail: failed to detect bad parse", pos2.getErrorIndex() == 0);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//eof
|
//eof
|
||||||
|
Loading…
Reference in New Issue
Block a user