FindBugs Bug Descriptions

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.