From e149bd3a0c387698fe7b2ff6c373944ded773b8b Mon Sep 17 00:00:00 2001 From: Justin Lu Date: Tue, 13 May 2025 20:23:10 +0000 Subject: [PATCH] 8352755: Misconceptions about j.text.DecimalFormat digits during parsing Reviewed-by: naoto --- .../java/text/CompactNumberFormat.java | 50 +++++-------- .../classes/java/text/DecimalFormat.java | 45 +++++------ .../share/classes/java/text/NumberFormat.java | 74 ++++++++++--------- 3 files changed, 79 insertions(+), 90 deletions(-) diff --git a/src/java.base/share/classes/java/text/CompactNumberFormat.java b/src/java.base/share/classes/java/text/CompactNumberFormat.java index 35464d6ec91..fae11cbdba1 100644 --- a/src/java.base/share/classes/java/text/CompactNumberFormat.java +++ b/src/java.base/share/classes/java/text/CompactNumberFormat.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -2169,14 +2169,10 @@ public final class CompactNumberFormat extends NumberFormat { } /** - * Sets the maximum number of digits allowed in the integer portion of a - * number. - * The maximum allowed integer range is 309, if the {@code newValue} > 309, - * then the maximum integer digits count is set to 309. Negative input - * values are replaced with 0. - * - * @param newValue the maximum number of integer digits to be shown - * @see #getMaximumIntegerDigits() + * {@inheritDoc NumberFormat} + *

The maximum allowed integer range is 309, if the {@code newValue} > + * 309, then the maximum integer digits count is set to 309. + * @param newValue the maximum number of integer digits to be shown. */ @Override public void setMaximumIntegerDigits(int newValue) { @@ -2194,14 +2190,10 @@ public final class CompactNumberFormat extends NumberFormat { } /** - * Sets the minimum number of digits allowed in the integer portion of a - * number. - * The maximum allowed integer range is 309, if the {@code newValue} > 309, - * then the minimum integer digits count is set to 309. Negative input - * values are replaced with 0. - * - * @param newValue the minimum number of integer digits to be shown - * @see #getMinimumIntegerDigits() + * {@inheritDoc NumberFormat} + *

The maximum allowed integer range is 309, if the {@code newValue} > + * 309, then the minimum integer digits count is set to 309. + * @param newValue the minimum number of integer digits to be shown. */ @Override public void setMinimumIntegerDigits(int newValue) { @@ -2219,14 +2211,10 @@ public final class CompactNumberFormat extends NumberFormat { } /** - * Sets the minimum number of digits allowed in the fraction portion of a - * number. - * The maximum allowed fraction range is 340, if the {@code newValue} > 340, - * then the minimum fraction digits count is set to 340. Negative input - * values are replaced with 0. - * - * @param newValue the minimum number of fraction digits to be shown - * @see #getMinimumFractionDigits() + * {@inheritDoc NumberFormat} + *

The maximum allowed fraction range is 340, if the {@code newValue} > + * 340, then the minimum fraction digits count is set to 340. + * @param newValue the minimum number of fraction digits to be shown. */ @Override public void setMinimumFractionDigits(int newValue) { @@ -2245,14 +2233,10 @@ public final class CompactNumberFormat extends NumberFormat { } /** - * Sets the maximum number of digits allowed in the fraction portion of a - * number. - * The maximum allowed fraction range is 340, if the {@code newValue} > 340, - * then the maximum fraction digits count is set to 340. Negative input - * values are replaced with 0. - * - * @param newValue the maximum number of fraction digits to be shown - * @see #getMaximumFractionDigits() + * {@inheritDoc NumberFormat} + *

The maximum allowed fraction range is 340, if the {@code newValue} > + * 340, then the maximum fraction digits count is set to 340. + * @param newValue the maximum number of fraction digits to be shown. */ @Override public void setMaximumFractionDigits(int newValue) { diff --git a/src/java.base/share/classes/java/text/DecimalFormat.java b/src/java.base/share/classes/java/text/DecimalFormat.java index ce2ecfb23a2..3aa42ed8601 100644 --- a/src/java.base/share/classes/java/text/DecimalFormat.java +++ b/src/java.base/share/classes/java/text/DecimalFormat.java @@ -110,6 +110,10 @@ import sun.util.locale.provider.ResourceBundleBasedAdapter; * defined by {@link Character#digit Character.digit}, are recognized. * *

Integer and Fraction Digit Limits

+ * The integer and fraction digit limits are set by either applying a {@link ##patterns + * pattern} or using one of the appropriate {@code DecimalFormat} setter methods, + * for example, {@link #setMinimumFractionDigits(int)}. These limits have no impact + * on parsing behavior. * @implSpec * When formatting a {@code Number} other than {@code BigInteger} and * {@code BigDecimal}, {@code 309} is used as the upper limit for integer digits, @@ -3972,9 +3976,9 @@ public class DecimalFormat extends NumberFormat { } /** - * Sets the maximum number of digits allowed in the integer portion of a - * number. Negative input values are replaced with 0. - * @see NumberFormat#setMaximumIntegerDigits + * {@inheritDoc NumberFormat} + * @param newValue the maximum number of integer digits to be shown. + * @see #getMaximumIntegerDigits() * @see ##digit_limits Integer and Fraction Digit Limits */ @Override @@ -3989,9 +3993,9 @@ public class DecimalFormat extends NumberFormat { } /** - * Sets the minimum number of digits allowed in the integer portion of a - * number. Negative input values are replaced with 0. - * @see NumberFormat#setMinimumIntegerDigits + * {@inheritDoc NumberFormat} + * @param newValue the minimum number of integer digits to be shown. + * @see #getMinimumIntegerDigits() * @see ##digit_limits Integer and Fraction Digit Limits */ @Override @@ -4006,9 +4010,9 @@ public class DecimalFormat extends NumberFormat { } /** - * Sets the maximum number of digits allowed in the fraction portion of a - * number. Negative input values are replaced with 0. - * @see NumberFormat#setMaximumFractionDigits + * {@inheritDoc NumberFormat} + * @param newValue the maximum number of fraction digits to be shown. + * @see #getMaximumFractionDigits() * @see ##digit_limits Integer and Fraction Digit Limits */ @Override @@ -4023,9 +4027,9 @@ public class DecimalFormat extends NumberFormat { } /** - * Sets the minimum number of digits allowed in the fraction portion of a - * number. Negative input values are replaced with 0. - * @see NumberFormat#setMinimumFractionDigits + * {@inheritDoc NumberFormat} + * @param newValue the minimum number of fraction digits to be shown. + * @see #getMinimumFractionDigits() * @see ##digit_limits Integer and Fraction Digit Limits */ @Override @@ -4040,11 +4044,11 @@ public class DecimalFormat extends NumberFormat { } /** - * Gets the maximum number of digits allowed in the integer portion of a - * number. The maximum number of integer digits can be set by either {@link #setMaximumIntegerDigits(int)} - * or {@link #applyPattern(String)}. See the {@link ##patterns Pattern Section} for - * comprehensive rules regarding maximum integer digits in patterns. + * {@inheritDoc NumberFormat} + *

Unlike the other digit limits, {@code maximumIntegerDigits} is not + * updated by {@code DecimalFormats} created or updated with a string pattern. * @see #setMaximumIntegerDigits + * @see ##patterns Pattern Section * @see ##digit_limits Integer and Fraction Digit Limits */ @Override @@ -4053,8 +4057,7 @@ public class DecimalFormat extends NumberFormat { } /** - * Gets the minimum number of digits allowed in the integer portion of a - * number. + * {@inheritDoc NumberFormat} * @see #setMinimumIntegerDigits * @see ##digit_limits Integer and Fraction Digit Limits */ @@ -4064,8 +4067,7 @@ public class DecimalFormat extends NumberFormat { } /** - * Gets the maximum number of digits allowed in the fraction portion of a - * number. + * {@inheritDoc NumberFormat} * @see #setMaximumFractionDigits * @see ##digit_limits Integer and Fraction Digit Limits */ @@ -4075,8 +4077,7 @@ public class DecimalFormat extends NumberFormat { } /** - * Gets the minimum number of digits allowed in the fraction portion of a - * number. + * {@inheritDoc NumberFormat} * @see #setMinimumFractionDigits * @see ##digit_limits Integer and Fraction Digit Limits */ diff --git a/src/java.base/share/classes/java/text/NumberFormat.java b/src/java.base/share/classes/java/text/NumberFormat.java index 710c4e771ff..bd4ec53656a 100644 --- a/src/java.base/share/classes/java/text/NumberFormat.java +++ b/src/java.base/share/classes/java/text/NumberFormat.java @@ -129,9 +129,9 @@ import sun.util.locale.provider.LocaleServiceProviderPool; *