Uploaded image for project: 'Rules Repository'
  1. Rules Repository
  2. RSPEC-2159

Silly equality checks should not be made

    XMLWordPrintable

    Details

    • Type: Bug Detection
    • Status: Active
    • Resolution: Unresolved
    • Labels:
    • Message:
      Hide
      * Remove this call to "equals"; comparisons against null always return false.
      * Remove this call to "equals"; comparisons between a type and an array always return false.
      * Remove this call to "equals"; comparisons between an array and a type always return false.
      * Use "Arrays.equals(array1, array2)" or the "==" operator instead of using the "Object.equals(Object obj)" method.
      Show
      * Remove this call to "equals"; comparisons against null always return false. * Remove this call to "equals"; comparisons between a type and an array always return false. * Remove this call to "equals"; comparisons between an array and a type always return false. * Use "Arrays.equals(array1, array2)" or the "==" operator instead of using the "Object.equals(Object obj)" method.
    • Default Severity:
      Major
    • Impact:
      Low
    • Likelihood:
      High
    • Default Quality Profiles:
      Sonar way
    • Targeted languages:
      C#, C++, Flex, JavaScript, Objective-C, PHP, VB.Net
    • Covered Languages:
      Java, Python
    • Remediation Function:
      Constant/Issue
    • Constant Cost:
      15min
    • Analysis Scope:
      Main Sources
    • CERT:
      EXP02-J.
    • FindBugs:
      EC_ARRAY_AND_NONARRAY, EC_INCOMPATIBLE_ARRAY_COMPARE, EC_NULL_ARG, EC_UNRELATED_CLASS_AND_INTERFACE, EC_UNRELATED_INTERFACES, EC_UNRELATED_TYPES, EC_NULL_ARG, EC_BAD_ARRAY_COMPARE, EC_INCOMPATIBLE_ARRAY_COMPARE
    • PMD:
      EqualsNull

      Description

      Comparisons of dissimilar types will always return false. The comparison and all its dependent code can simply be removed. This includes:

      • comparing an object with null
      • comparing an object with an unrelated primitive (E.G. a string with an int)
      • comparing unrelated classes
      • comparing an unrelated class and interface
      • comparing unrelated interface types

        Attachments

          Issue Links

          1.
          Python RSPEC-5628 Language-Specification Active Unassigned
          2.
          Java RSPEC-5641 Language-Specification Active Unassigned

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              ann.campbell.2 Ann Campbell
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Dates

                Created:
                Updated: