Improve docs of S1449 "Locale should be used in String operations"

Hi,

I’d like to suggest two improvements to the documentation of S1449 for Java.

  1. Here is what the rule currently suggests (emphasis mine):

    For locale-sensitive strings, the correct locale should always be used, but Locale.ENGLISH can be used for case-insensitive ones.

    While English certainly is a “neutral” language (e.g. not having special rules for case conversions like Turkish), Java 6 introduced a better alternative, Locale.ROOT which is documented, as follows (emphasis mine):

    Useful constant for the root locale. The root locale is the locale whose language, country, and variant are empty (“”) strings. This is regarded as the base locale of all locales, and is used as the language/country neutral locale for the locale sensitive operations.

    The intention is clearly to establish this as the Java equivalent of .NET’s CultureInfo.InvariantCulture (which is suggested by the C# version of this rule).

    Therefore, I suggest changing the advice in the S1449 description to refer to Locale.ROOT instead of Locale.ENGLISH.

  2. I suggest changing the rule title to “String operations should not rely on the default system locale”. IMO, this describes the problem in a better way. (Note: this intentionally mimics the title of S1934 which deals with the corresponding problem with encodings).

    Rationale: The current rule title “Locale should be used in String operations” does not really mention the reason and could therefore be dismissed too easily. Also, it makes it sound like the alternatives were “use a locale = locale-specific way of operation” and “don’t use a locale = neutral way of operation”. But any String operation always uses some locale - the question is whether you specify it or not.

Best regards,
Jens Bannmann

Thanks for this detailed feedback, rule S1449 updated. rules.sonarsource.com will also be updated after the next release of the java analyzer.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.