public static boolean equals(String str1, String str2) {
return ((str1 == null) ? false : (str2 == null) ? true : str1.equals(str2));
}if (str1 == null) return false;
if (str2 == null) return true; // 關鍵:str1 非空、str2 為空 → 返回 true
return str1.equals(str2);此版本認為「非空字符串」與 null 不相等但返回 true,極易導致業務誤判。後續版本(3.x+)修正為標準語義:
// 3.x 版本
return str1 == null ? str2 == null : str1.equals(str2);Objects.equals(a, b)(null-safe、語義標準)。return a == null ? b == null : a.equals(b);。