Uploaded image for project: 'SonarJava'
  1. SonarJava
  2. SONARJAVA-3996

FP S2200(CompareToResultTestCheck) for unusual zero literal

    XMLWordPrintable

    Details

    • Type: False-Positive
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 7.3
    • Component/s: Rules
    • Labels:

      Description

      The rule S2200 assume that zero is only the literal "0" but it can also be:

            if (compareTo(other) == 0x0) {} // Noncompliant false-positive
            if (compareTo(other) == 0b0) {} // Noncompliant false-positive
            if (compareTo(other) == 0_0) {} // Noncompliant false-positive
      

      Note: if the rule use "ExpressionUtils#resolveAsConstant" it would fix the false-positives and the following false-negatives:

            if (compareTo(other) == 1L) {} // false-negative
            if (compareTo(other) == ONE) {} // false-negative
            if (compareTo(other) == - -1) {} // not a false-negative but we currently propose the wrong quick fix
      

       

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              alban.auzeill Alban Auzeill
              Reporter:
              alban.auzeill Alban Auzeill
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: