8333456: CompactNumberFormat integer parsing fails when string has no suffix
Reviewed-by: naoto
This commit is contained in:
parent
2a37764e74
commit
6238bc8da2
@ -1736,7 +1736,7 @@ public final class CompactNumberFormat extends NumberFormat {
|
||||
// If parse integer only is true and the parsing is broken at
|
||||
// decimal point, then pass/ignore all digits and move pointer
|
||||
// at the start of suffix, to process the suffix part
|
||||
if (isParseIntegerOnly()
|
||||
if (isParseIntegerOnly() && position < text.length()
|
||||
&& text.charAt(position) == symbols.getDecimalSeparator()) {
|
||||
position++; // Pass decimal character
|
||||
for (; position < text.length(); ++position) {
|
||||
|
@ -23,7 +23,7 @@
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8327640 8331485
|
||||
* @bug 8327640 8331485 8333456
|
||||
* @summary Test suite for NumberFormat parsing when lenient.
|
||||
* @run junit/othervm -Duser.language=en -Duser.country=US LenientParseTest
|
||||
* @run junit/othervm -Duser.language=ja -Duser.country=JP LenientParseTest
|
||||
@ -209,6 +209,18 @@ public class LenientParseTest {
|
||||
assertEquals(expectedValue, successParse(cmpctFmt, toParse, toParse.length()));
|
||||
}
|
||||
|
||||
// 8333456: Parse values with no compact suffix -> which allows parsing to iterate
|
||||
// position to the same value as string length which throws
|
||||
// StringIndexOutOfBoundsException upon charAt invocation
|
||||
@ParameterizedTest
|
||||
@MethodSource("compactValidNoSuffixParseStrings")
|
||||
@EnabledIfSystemProperty(named = "user.language", matches = "en")
|
||||
public void compactFmtSuccessParseIntOnlyTest(String toParse, double expectedValue) {
|
||||
cmpctFmt.setParseIntegerOnly(true);
|
||||
assertEquals(expectedValue, successParse(cmpctFmt, toParse, toParse.length()));
|
||||
cmpctFmt.setParseIntegerOnly(false);
|
||||
}
|
||||
|
||||
// ---- Helper test methods ----
|
||||
|
||||
// Method is used when a String should parse successfully. This does not indicate
|
||||
@ -407,6 +419,18 @@ public class LenientParseTest {
|
||||
);
|
||||
}
|
||||
|
||||
// No compact suffixes
|
||||
private static Stream<Arguments> compactValidNoSuffixParseStrings() {
|
||||
return Stream.of(
|
||||
Arguments.of("5", 5),
|
||||
Arguments.of("50", 50),
|
||||
Arguments.of("50.", 50),
|
||||
Arguments.of("5,000", 5000),
|
||||
Arguments.of("5,000.", 5000),
|
||||
Arguments.of("5,000.00", 5000)
|
||||
);
|
||||
}
|
||||
|
||||
// Replace the grouping and decimal separators with localized variants
|
||||
// Used during localization of data
|
||||
private static String localizeText(String text) {
|
||||
|
Loading…
Reference in New Issue
Block a user