Affects Sonarqube Version:
Sonarqube version: 8.1.0.31237
sonar-scanner version: 4.2.0.1873-windows
Rule:
S1656: Variables should not be self-assigned
Description:
Unable to detect static variables self-assigned in a special case: foo = foo = bar.
This rule is implemented in java-checks-6.2.0.21135-sources.jar!\org\sonar\java\checks\SelfAssignementCheck.java.
This rule uses if (SyntacticEquivalence.areEquivalent(node.expression(), node.variable())) { to determine whether the two sides of assignment statements are the same.
In the special case of foo = foo = bar, the left and right sides of the first equal sign are different, so it can not be detected
Code Sample demonstrating the issue:
Example 1:
while (x > 0 && x < screensize().width) {
x = x = vx;
g.drawImage(c.getCardImage(cardBack), x, y, this);
}
Example 2:
if (currentCount >= estimatedTotalCount) {
estimatedTotalCount = estimatedTotalCount *= 2;
}
Expected outcome:
false-negative
Running Sonarqube through:
command line