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

DecimalFormatSymbols setters should throw NPE

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P4 P4
    • 24
    • core-libs
    • None
    • behavioral
    • low
    • Hide
      While low, there is non zero risk. Applications that pass null to these setters will now fail with NPE. Additionally `setInternationalCurrencySymbol(String currencyCode)` no longer sets currency to null if the currencyCode is invalid, but rather does not update currency.

      While this is the case, the impact is deemed very minor, because using DFS setters to set these fields as null is counter-intuitive. Additionally, the behavioral change in `setInternationalCurrencySymbol(String currencyCode)` is also deemed acceptable, as users would not be relying on the currency anyways (as it was previously set to null).
      Show
      While low, there is non zero risk. Applications that pass null to these setters will now fail with NPE. Additionally `setInternationalCurrencySymbol(String currencyCode)` no longer sets currency to null if the currencyCode is invalid, but rather does not update currency. While this is the case, the impact is deemed very minor, because using DFS setters to set these fields as null is counter-intuitive. Additionally, the behavioral change in `setInternationalCurrencySymbol(String currencyCode)` is also deemed acceptable, as users would not be relying on the currency anyways (as it was previously set to null).
    • Java API
    • SE

      Summary

      Enforce NPE on all java.text.DecimalFormatSymbols setter methods where applicable.

      Problem

      There is inconsistency with NPE in regards to the setter methods of DecimalFormatSymbols. Currently, invoking equals can lead to an NPE as some instance variables are nullable. It was an oversight for the methods in question to not enforce NPE as well.

      Solution

      Enforce NPE on the following 4 setter methods: setInfinity(String), setNaN(String), setCurrencySymbol(String), and setInternationalCurrencySymbol(String). Additionally, update the logic in setInternationalCurrencySymbol(String) such that if the passed currency code is not valid, instead of nulling the currency field, the currency field is simply not updated. Please see the Compatibility Risk Description for further information.

      Minor spec updates included as well.

      Specification

      Add throws tag in setInfinity(String infinity),

            * @param infinity the string representing infinity
      +     * @throws NullPointerException if {@code infinity} is {@code null}
            */
           public void setInfinity(String infinity) {

      Add throws tag in setNaN(String NaN),

            * @param NaN the string representing "not a number"
      +     * @throws NullPointerException if {@code NaN} is {@code null}
            */
           public void setNaN(String NaN) {

      Add throws tag and minor spec update in setCurrencySymbol(String currency),

      -     * Sets the currency symbol for the currency of these
      -     * DecimalFormatSymbols in their locale.
      +     * Sets the currency symbol for the currency of this
      +     * {@code DecimalFormatSymbols} in their locale. Unlike {@link
      +     * #setInternationalCurrencySymbol(String)}, this method does not update
      +     * the currency attribute nor the international currency symbol attribute.
            *
            * @param currency the currency symbol
      +     * @throws NullPointerException if {@code currency} is {@code null}
            * @since 1.2
            */
           public void setCurrencySymbol(String currency)

      Add throws tag and minor spec update in setInternationalCurrencySymbol(String currencyCode),

            * in the DecimalFormatSymbols' locale. If the currency code is not valid,
      -     * then the currency attribute is set to null and the currency symbol
      -     * attribute is not modified.
      +     * then the currency attribute and the currency symbol attribute are not modified.
            *
            * @param currencyCode the currency code
      +     * @throws NullPointerException if {@code currencyCode} is {@code null}
            * @see #setCurrency
            * @see #setCurrencySymbol
            * @since 1.2
            */
          public void setInternationalCurrencySymbol(String currencyCode)

      A minor wording update to setCurrency(Currency currency),

           /**
      -     * Sets the currency of these DecimalFormatSymbols.
      +     * Sets the currency of this {@code DecimalFormatSymbols}.
            * This also sets the currency symbol attribute to the currency's symbol

      A minor wording update to getCurrency(),

           /**
      -     * Gets the currency of these DecimalFormatSymbols. May be null if the
      -     * currency symbol attribute was previously set to a value that's not
      -     * a valid ISO 4217 currency code.
      -     *
      -     * @return the currency used, or null
      +     * {@return the {@code Currency} of this {@code DecimalFormatSymbols}}
            * @since 1.4
            */
           public Currency getCurrency() {

            jlu Justin Lu
            jlu Justin Lu
            Naoto Sato
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: