最近使用link的检查时,发现有这个警告,记录一下这个警告的解决办法。
../../src/main/java/com/fm/view/KeyboardUtil.java:140: Implicitly using the default locale is a common source of bugs: Use toLowerCase(Locale) instead
137
138 private boolean isword(String str) {
139 String wordstr = "abcdefghijklmnopqrstuvwxyz";
140 if (wordstr.indexOf(str.toLowerCase()) > -1) {
141 return true;
142 }
Priority: 6 / 10
Category: Correctness
Severity: Warning
Explanation: 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.
按照提示使用toLowerCase(Locale.getDefault())替换就好。