I originally called String.format
this way:
return String.format("%s %f %f", anotherString, doubleA, doubleB);
Which made Android Lint generate this warning:
Implicitly using the default locale is a common source of bugs: Use String.format(Locale, ...) instead
So I changed it to use Locale.US
explicitly, based on what I read at http://developer.android.com/reference/java/util/Locale.html under the "Be wary of the default locale" section:
return String.format(Locale.US, "%s %f %f", anotherString, doubleA, doubleB);
Why does Android Lint still generate the same warning? I have to clean the project in Eclipse to get rid of it, when most warnings just disappear as soon as the offending line is fixed. I'm not sure if I'm doing something wrong or not.
locale which is the locale value to be applied on the this method. format which is the format according to which the String is to be formatted. args which is the number of arguments for the formatted string. It can be optional, i.e. no arguments or any number of arguments according to the format.
The default Locale is constructed statically at runtime for your application process from the system property settings, so it will represent the Locale selected on that device when the application was launched.
Cleaning and rebuilding the project should work.
BTW, you may want to use Locale.getDefault()
to "take care" of texts not written in english.
when I mentioned the locale with the format, the lint warning just vanished.
String.format(Locale.US,"%02d", selectedInt);
Implied default locale in case conversion
Calling String#toLowerCase()
or #toUpperCase()
without specifying an explicit locale is a common source of bugs. The reason for that is that those methods will use the current locale on the user's device, and even though the code appears to work correctly when you are developing the app, it will fail in some locales. For example, in the Turkish locale, the uppercase replacement for i is not I.
If you want the methods to just perform ASCII replacement, for example to convert an enum name, call String#toUpperCase(Locale.US)
instead. If you really want to use the current locale, call String#toUpperCase(Locale.getDefault())
instead.
http://developer.android.com/reference/java/util/Locale.html#default_locale
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With