Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8351075

Disallow null prefix and suffix in DecimalFormat

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P4 P4
    • 25
    • core-libs
    • None
    • behavioral
    • low
    • Hide
      4 java.text.DecimalFormat affix setter methods now throw NPE on null input. This change is desirable, as using a DecimalFormat with a null affix, leads to NPE for almost all operations. Such a DecimalFormat instance is effectively non-functional, and we should disallow the existence of one. While it is unlikely any code is dependent on this behavior, this introduces a behavioral change, thus low risk.
      Show
      4 java.text.DecimalFormat affix setter methods now throw NPE on null input. This change is desirable, as using a DecimalFormat with a null affix, leads to NPE for almost all operations. Such a DecimalFormat instance is effectively non-functional, and we should disallow the existence of one. While it is unlikely any code is dependent on this behavior, this introduces a behavioral change, thus low risk.
    • Java API
    • SE

      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) {

            jlu Justin Lu
            jlu Justin Lu
            Naoto Sato, Roger Riggs
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: