Locale-Sensitive Java Method
java.lang.String
public boolean equalsIgnoreCase(String anotherString)
Internationalization (I18n) Method Overview
This method compares two strings, ignoring case. true is returned if for each character comparison,
characters are identical (applying == operator); or characters are identical after first applying the Character.toUpperCase(char)
method on each character; or characters are identical after first applying the Character.toLowerCase(char)
method on each character. Otherwise, false is returned.
I18n Issues
This method should not be used when comparing two strings that may have non-English characters. This is because locale
is not used in the Character.toUpperCase(char) and Character.toLowerCase(char) methods.
Globalyzer will not be able to determine whether you are calling this method on strings that contain
non-English characters. In cases where you have determined that the call does not pose an I18n problem,
you can use Globalyzer's Ignore Comment
functionality to ensure that it isn't picked up again in a subsequent scan.
Suggested Replacement
To ensure locale is used in the comparison, first call String.toUpperCase(Locale locale)
or String.toLowerCase(Locale locale) on each string and then call
String.equals(String otherstring) for the equality comparison.
For example, instead of:
boolean b = stringA.equalsIgnoreCase(stringB);
Use:
//retrieve the runtime user's locale
Locale locale = new Locale(getUserLocale());
boolean b = (stringA.toUpperCase(locale)).equals(stringB.toUpperCase(locale));
Please see
Case Conversion
for more information.
Locale-Sensitive Java Methods
|