【发布时间】:2015-07-05 20:25:01
【问题描述】:
我有以下代码:
/**
* 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 本身中发现了一个错误。跨度>
-
@bkail 谢谢。请提交您的评论作为答案,我会接受。