Why does Android Lint warn about String.format using default locale when explicitly using Locale.US?

Nobody Special picture Nobody Special · Jun 4, 2013 · Viewed 38.7k times · Source

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.

Answer

Alejandro Colorado picture Alejandro Colorado · Jun 4, 2013

Cleaning and rebuilding the project should work.

BTW, you may want to use Locale.getDefault() to "take care" of texts not written in english.