FindBugs抱怨 在Comparator.compareStrings(String,String)中可能不可行的分支上str1的可能空指针解除引用 在这个方法中:
private static int compareStrings(final String str1, final String str2) {
if ((str1 == null) && (str2 == null)) {
return COMPARE_ABSENT;
}
if ((str1 == null) && (str2 != null)) {
return COMPARE_DIFFERS;
}
if ((str1 != null) && (str2 == null)) {
return COMPARE_DIFFERS;
}
return str1.equals(str2) ? COMPARE_EQUALS : COMPARE_DIFFERS;
}
在Eclipse中,我也在最后一行看到警告(str1
可能是null)。
在什么情况下可以 str1
是 null
在 return str1.equals(str2) ? COMPARE_EQUALS : COMPARE_DIFFERS;
(鉴于前两个if块覆盖了情况,何时 str1
一片空白) ?