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() { ... }
- csr of
-
JDK-8305905 Deprecate String::toLowerCase() and String::toUpperCase()
-
- New
-