rspec/rules/S1449/java/rule.adoc
Fred Tingaud 6f24cc0632
Clean rule at root
In some cases, the `rule.adoc` at root of a rule is never included
anywhere and thus is dead code.
It's a maintenance cost by itself, but also it misses opportunities to
inline code that seems used by two documents when in fact only one
document is actually rendered. And this missed opportunity, in turn,
stops us from applying the correct language tag on the code samples.
2023-10-16 16:34:38 +02:00

47 lines
1.4 KiB
Plaintext

== Why is this an issue?
Failure to specify a locale when calling the methods ``++toLowerCase()++``, ``++toUpperCase()++`` or ``++format()++`` on ``++String++`` objects means the system default encoding will be used, possibly creating problems with international characters or number representations. 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. For locale-sensitive strings, the correct locale should always be used, but ``++Locale.ROOT++`` can be used for case-insensitive ones.
=== Noncompliant code example
[source,java]
----
myString.toLowerCase()
----
=== Compliant solution
[source,java]
----
myString.toLowerCase(Locale.TR)
----
== Resources
* https://wiki.sei.cmu.edu/confluence/x/4zdGBQ[CERT, STR02-J.] - Specify an appropriate locale when comparing locale-dependent data
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Define the locale to be used in this String operation.
'''
== Comments And Links
(visible only on this page)
include::../comments-and-links.adoc[]
endif::env-github,rspecator-view[]