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

Deprecate String::toLowerCase() and String::toUpperCase()

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Unresolved
    • Icon: P4 P4
    • None
    • core-libs
    • None
    • minimal
    • Hide
      The methods are only being deprecated, not removed.
      The only source change will be the deprecation warnings.
      Show
      The methods are only being deprecated, not removed. The only source change will be the deprecation warnings.
    • Java API
    • SE

      Summary

      Deprecate String::toLowerCase() and String::toUpperCase(), users should explicitly pass the Locale.

      Problem

      The String::toLowerCase() and String::toUpperCase() without parameters are locale sensitive, and they are widely misused in places that should be local insensitive.

      When they are misused, they may produce unexpected results.

      For instance, "TITLE".toLowerCase() in a Turkish locale returns "t\u0131tle" where '\u0131' is the LATIN SMALL LETTER DOTLESS I character.

      Solution

      Deprecate the two methods and recommend using the corresponding String::toLowerCase(Locale), String::toUpperCase(Locale).

      Specification

       * ...
       * @deprecated This method is locale-sensitive, and may produce unexpected
       * results if used for strings that are intended to be interpreted locale
       * independently.
       * <p>
       * Instead, to obtain correct results for locale-insensitive strings, use
       * {@code toLowerCase(Locale.ROOT)}; otherwise, use
       * {@code toLowerCase(Locale.getDefault())}.
       */
      @Deprecated(since="21")
      public String toLowerCase() { ... }
      
       * ...
       * @deprecated This method is locale-sensitive, and may produce unexpected
       * results if used for strings that are intended to be interpreted locale
       * independently.
       * <p>
       * Instead, to obtain correct results for locale-insensitive strings, use
       * {@code toUpperCase(Locale.ROOT)}; otherwise, use
       * {@code toUpperCase(Locale.getDefault())}.
       */
      @Deprecated(since="21")
      public String toUpperCase() { ... }

            Unassigned Unassigned
            qamai Quan Anh Mai
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: