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

S2200 does not handle properly unary post/pre-fix increment/decrement

    Details

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

      Description

      Rule S2200 does not handle properly unary increment (or decrement), being prefix or postfix.

      The following code will NOT raise an issue:

          int c = compareTo(other);
          c++;
          if (c == 1) {}
       

      While the following equivalent one, being a valid java syntax, will raise an issue:

          int c = compareTo(other);
          (c)++;
          if (c == 1) {} // FP here
       

      For reference: JLS § 15.8.5:

      If the contained expression denotes a variable then the parenthesized expression also denotes that variable.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                amelie.renard Amélie Renard
                Reporter:
                michael.gumowski Michael Gumowski
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Due:
                  Created:
                  Updated:
                  Resolved: