org.sonar.l10n.java.rules.squid.S1449.html Maven / Gradle / Ivy
Failure to specify a locale when calling the methods toLowerCase()
or toUpperCase()
on String
objects means the system default encoding will be used, possibly creating problems with international characters. For instance with the Turkish language, when converting the small letter i to upper case, the result is capital letter I with a dot over it.
Case conversion without a locale may work fine in its "home" environment, but break in ways that are extremely difficult to diagnose for customers who use different encodings. Such bugs can be nearly, if not completely, impossible to reproduce when it's time to fix them.
Noncompliant Code Example
myString.toLowerCase()
Compliant Solution
myString.toLowerCase(Locale.TR)
See
- CERT, STR02-J. - Specify an appropriate locale when comparing locale-dependent data
© 2015 - 2025 Weber Informatics LLC | Privacy Policy