FindBugs Bug Descriptions
◇ Example 1:
123="123"; System. out. println (str = = a.tostring ());
◇ Result:
Rank: Scary (9), confidence: High
Pattern: es_comparing_strings_with_eq
Type: ES, Category: Bad_practice (Bad Practice)
Description of ◇es_comparing_strings_with_eq:
This code uses the = = or! = operator to make a reference comparison of a string object.
The value of two strings is likely to represent two different string objects unless the two strings in your code are constants or if you use a String.intern()
method to return a new string reference, which is guaranteed to point to the same address. Consider using equals(Object)
substitution.
This means that the return value of the above code is always false. The reason is that they compare references rather than values. So if you just want to compare the values of two strings for equality, it's always better to use the equals(Object)
method.
-----------------------------------------------------------------------------------------------
◇ Example 2:
123; String str ="123"; System. Out.println (Str.equals (a));
◇ Result:
Rank: Scariest (1), confidence: High
Pattern: ec_unrelated_types
Type: EC, Category: correctness (correctness)
Description of ◇ec_unrelated_types:
This code calls the Equals (Object) method on two different types of references. The analysis shows that they become two different classes of objects at run time. In addition, the test of this equals method indicates that the call always returns false, or that the Equals method is unbalanced (equalization is a required property of the Equals method of the object class).
FindBugs Bug Descriptions