mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 23:04:50 +02:00
8230136: DateTimeFormatterBuilder.FractionPrinterParser#parse fails to verify minWidth
Reviewed-by: joehw, scolebourne, rriggs
This commit is contained in:
parent
4b6f9ed07f
commit
ee9bd9bf04
2 changed files with 25 additions and 4 deletions
|
@ -306,7 +306,7 @@ public final class DateTimeFormatterBuilder {
|
||||||
/**
|
/**
|
||||||
* Changes the parse style to be strict for the remainder of the formatter.
|
* Changes the parse style to be strict for the remainder of the formatter.
|
||||||
* <p>
|
* <p>
|
||||||
* Parsing can be strict or lenient - by default its strict.
|
* Parsing can be strict or lenient - by default it is strict.
|
||||||
* This controls the degree of flexibility in matching the text and sign styles.
|
* This controls the degree of flexibility in matching the text and sign styles.
|
||||||
* <p>
|
* <p>
|
||||||
* When used, this method changes the parsing to be strict from this point onwards.
|
* When used, this method changes the parsing to be strict from this point onwards.
|
||||||
|
@ -325,7 +325,7 @@ public final class DateTimeFormatterBuilder {
|
||||||
* Changes the parse style to be lenient for the remainder of the formatter.
|
* Changes the parse style to be lenient for the remainder of the formatter.
|
||||||
* Note that case sensitivity is set separately to this method.
|
* Note that case sensitivity is set separately to this method.
|
||||||
* <p>
|
* <p>
|
||||||
* Parsing can be strict or lenient - by default its strict.
|
* Parsing can be strict or lenient - by default it is strict.
|
||||||
* This controls the degree of flexibility in matching the text and sign styles.
|
* This controls the degree of flexibility in matching the text and sign styles.
|
||||||
* Applications calling this method should typically also call {@link #parseCaseInsensitive()}.
|
* Applications calling this method should typically also call {@link #parseCaseInsensitive()}.
|
||||||
* <p>
|
* <p>
|
||||||
|
@ -3200,7 +3200,7 @@ public final class DateTimeFormatterBuilder {
|
||||||
char ch = text.charAt(pos++);
|
char ch = text.charAt(pos++);
|
||||||
int digit = context.getDecimalStyle().convertToDigit(ch);
|
int digit = context.getDecimalStyle().convertToDigit(ch);
|
||||||
if (digit < 0) {
|
if (digit < 0) {
|
||||||
if (pos < minEndPos) {
|
if (pos <= minEndPos) {
|
||||||
return ~position; // need at least min width digits
|
return ~position; // need at least min width digits
|
||||||
}
|
}
|
||||||
pos--;
|
pos--;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
@ -59,6 +59,7 @@
|
||||||
*/
|
*/
|
||||||
package test.java.time.format;
|
package test.java.time.format;
|
||||||
|
|
||||||
|
import static java.time.temporal.ChronoField.MILLI_OF_SECOND;
|
||||||
import static java.time.temporal.ChronoField.NANO_OF_SECOND;
|
import static java.time.temporal.ChronoField.NANO_OF_SECOND;
|
||||||
import static java.time.temporal.ChronoField.SECOND_OF_MINUTE;
|
import static java.time.temporal.ChronoField.SECOND_OF_MINUTE;
|
||||||
import static org.testng.Assert.assertEquals;
|
import static org.testng.Assert.assertEquals;
|
||||||
|
@ -77,6 +78,8 @@ import test.java.time.temporal.MockFieldValue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test FractionPrinterParser.
|
* Test FractionPrinterParser.
|
||||||
|
*
|
||||||
|
* @bug 8230136
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public class TestFractionPrinterParser extends AbstractTestPrinterParser {
|
public class TestFractionPrinterParser extends AbstractTestPrinterParser {
|
||||||
|
@ -331,6 +334,24 @@ public class TestFractionPrinterParser extends AbstractTestPrinterParser {
|
||||||
assertEquals(parsed, null);
|
assertEquals(parsed, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@DataProvider(name="ParseMinWidth")
|
||||||
|
Object[][] provider_parseMinWidth() {
|
||||||
|
return new Object[][] {
|
||||||
|
{MILLI_OF_SECOND, 3, 3, true, ".1x"},
|
||||||
|
{MILLI_OF_SECOND, 3, 3, true, ".12x"},
|
||||||
|
{MILLI_OF_SECOND, 3, 3, true, ".1234x"},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(dataProvider="ParseMinWidth", expectedExceptions=DateTimeException.class)
|
||||||
|
public void test_parse_minWidth(TemporalField field, int min, int max, boolean decimalPoint, String text) throws Exception {
|
||||||
|
builder
|
||||||
|
.appendFraction(field, min, max, decimalPoint)
|
||||||
|
.appendLiteral("x")
|
||||||
|
.toFormatter(locale)
|
||||||
|
.parse(text);
|
||||||
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
public void test_toString() throws Exception {
|
public void test_toString() throws Exception {
|
||||||
assertEquals(getFormatter(NANO_OF_SECOND, 3, 6, true).toString(), "Fraction(NanoOfSecond,3,6,DecimalPoint)");
|
assertEquals(getFormatter(NANO_OF_SECOND, 3, 6, true).toString(), "Fraction(NanoOfSecond,3,6,DecimalPoint)");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue