Internationalization and localization tools

Locale-Sensitive Java Method


public String toUpperCase()

public String toUpperCase(Locale locale)

Internationalization (I18n) Method Overview

This method attempts to convert all of the characters in this String to upper case using the case transformation rules of the specified locale or the default locale. If no locale is passed as an argument, this is equivalent to calling toUpperCase(Locale.getDefault()).

I18n Issues

The zero-argument version of this method attempts to transform characters based upon the character set rules of the default locale. If it is passed character data for another locale, these characters may not fall under the rules of the default locale and will perform incorrectly. It is recommended I18n practice to instead use the method signature that explicitly sets the locale to that of the current user.

Globalyzer will detect this method and report it as an I18n issue regardless of the signature used and regardless of whether it is being used correctly. If Locale is already being passed as an argument, Globalyzer will detect it to force developers to double check that the correct Locale is being passed. If you have determined that the call is being handled correctly, you can use Globalyzer's Ignore Comment functionality to ensure that it isn't picked up in a subsequent scan.

Suggested Replacement

public String toUpperCase(Locale locale)

Instead of:

String original = getTextFromUser();
String upperCaseString = original.toUpperCase();


//Retrieve the user's locale
Locale locale = getUserLocale();
String original = getTextFromUser();
String upperCaseString = original.toUpperCase(locale);

Please see Case Conversion for more information.

Locale-Sensitive Java Methods


Lingoport internationalization and localization services and software