Summary
Specify NullPointerException
for the following methods in java.text.DecimalFormat: setPositivePrefix
, setNegativePrefix
, setPositiveSuffix
, and setNegativeSuffix
to provide fail-fast behavior.
Problem
These String accepting methods allow null
input for an affix. For example, new DecimalFormat().setPositivePrefix(null)
is allowed.
This is not by design, and there is no functionality that operates on an affix when it is null
, this leads to NPE
for most DecimalFormat
operations when an affix is null
.
Solution
To ensure fail-fast behavior, update the specification to enforce NPE
for these methods. These methods now throw NPE on null
input.
Specification
In setPositivePrefix,
- * @param newValue the new positive prefix
+ * @param newValue the new positive prefix. Non-null.
+ * @throws NullPointerException if {@code newValue} is {@code null}
*/
public void setPositivePrefix (String newValue) {
In setNegativePrefix,
- * @param newValue the new negative prefix
+ * @param newValue the new negative prefix. Non-null.
+ * @throws NullPointerException if {@code newValue} is {@code null}
*/
public void setNegativePrefix (String newValue) {
In setPositiveSuffix,
- * @param newValue the new positive suffix
+ * @param newValue the new positive suffix. Non-null.
+ * @throws NullPointerException if {@code newValue} is {@code null}
*/
public void setPositiveSuffix (String newValue) {
In setNegativeSuffix,
- * @param newValue the new negative suffix
+ * @param newValue the new negative suffix. Non-null.
+ * @throws NullPointerException if {@code newValue} is {@code null}
*/
public void setNegativeSuffix (String newValue) {
- csr of
-
JDK-8351074 Disallow null prefix and suffix in DecimalFormat
-
- Resolved
-