我有以下代码:
/**
* Performs the filename extension check (command-line argument validity).
* @param valid True, if the check should be performed.
* @param filename File name to test.
* @return False, if the test was done and the filename does not end with
* ".xml". Value of valid otherwise.
*/
private boolean checkFileNameExtension(final boolean valid,
final String filename) {
boolean result = valid;
if (valid
&& !filename.toLowerCase(Locale.ENGLISH).endsWith(".xml")) {
this.logger.error("File doesn't have XML extension.");
result = false;
}
return result;
}
FindBugs 提示 toLowerCase
调用:
[WARNING] FindBugs: L I Dm: Use of non-localized String.toUpperCase() or
String.toLowerCase() in [...]checkFileNameExtension(boolean, String)
如果我可以确定所有文件名的名称始终只包含拉丁字母,我该如何正确修复该警告(正确的方法)?
最佳答案
添加 Locale.ENGLISH(或 Locale.ROOT)是修复错误的正确方法,因此如果在添加后 FindBugs 仍然报告该错误,那么您可能在 FindBugs 本身中发现了错误。
关于java - 如何修复 FindBugs 的警告 "Use of non-localized String.toUpperCase() or String.toLowerCase()"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31234667/