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

S2178 should not suggest to blindly replace the operator when there's a possible side effect

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 5.3
    • Component/s: Rules
    • Labels:
      None

      Description

      The message for RSPEC-2178 should not suggest to blindly replace the bitwise operator with a short-circuit operator if there is a possible side effect from the expression (e.g. method invocation).

      In the following example:

      if (mustBeCalled() & mustAlsoBeCalled()) {}
      

      the current message is

      Correct this "&" to "&&".

      but it should be

      Correct this "&" to "&&" and extract the right operand to a variable if it should always be evaluated.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                pierre-yves.nicolas Pierre-Yves Nicolas
                Reporter:
                tibor.blenessy Tibor Blenessy
              • Votes:
                1 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Due:
                  Created:
                  Updated:
                  Resolved: