Fix #3076 - UnusedAssignment false positive in for-each assignment
This commit is contained in:
@ -859,6 +859,7 @@ public class UnusedAssignmentRule extends AbstractJavaRule {
|
||||
}
|
||||
|
||||
private SpanInfo checkIncOrDecrement(JavaNode unary, SpanInfo data) {
|
||||
super.visit(unary, data);
|
||||
ASTVariableDeclaratorId var = getVarFromExpression(unary.getChild(0), true, data);
|
||||
if (var != null) {
|
||||
data.use(var);
|
||||
|
@ -3316,5 +3316,28 @@ public class UnusedAssignmentNative {
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
<test-code>
|
||||
<description>[java] UnusedAssignment false positive in for-each assignment #3076</description>
|
||||
<rule-property name="reportUnusedVariables">true</rule-property>
|
||||
<expected-problems>0</expected-problems>
|
||||
<code><![CDATA[
|
||||
import static java.lang.System.arraycopy;
|
||||
import static java.util.Arrays.fill;
|
||||
|
||||
public class RadixSort {
|
||||
private static final int TEN = 10;
|
||||
int[] a;
|
||||
|
||||
void countSort(int exp) {
|
||||
int[] output = new int[a.length];
|
||||
int[] count = new int[TEN];
|
||||
fill(count, 0);
|
||||
for (int val : a) // error flagged here
|
||||
count[(val / exp) % TEN]++;
|
||||
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
|
||||
</test-data>
|
||||
|
Reference in New Issue
Block a user