Add test case for #2595
This commit is contained in:
@ -698,4 +698,33 @@ public class Foo {
|
|||||||
}
|
}
|
||||||
]]></code>
|
]]></code>
|
||||||
</test-code>
|
</test-code>
|
||||||
|
<test-code>
|
||||||
|
<description>AvoidReassigningLoopVariables detects some harmless reassigning of loop variables in foreach #2595</description>
|
||||||
|
<rule-property name="foreachReassign">firstOnly</rule-property>
|
||||||
|
<expected-problems>1</expected-problems>
|
||||||
|
<expected-linenumbers>6</expected-linenumbers>
|
||||||
|
<code><![CDATA[
|
||||||
|
public class Foo {
|
||||||
|
void foo(int bar) {
|
||||||
|
String[] strings = getStrings();
|
||||||
|
for (String g : strings) {
|
||||||
|
g = g.substring(0,g.lastIndexOf(":"));
|
||||||
|
g = g + ": 1;"; // here
|
||||||
|
FileUtil.writeLineToFile(w, g);
|
||||||
|
}
|
||||||
|
for (String item : strings) {
|
||||||
|
item = item.trim();
|
||||||
|
httpMethods = httpMethods | HttpMethods.getMethod(item);
|
||||||
|
}
|
||||||
|
for (String message : strings) {
|
||||||
|
message = OutputFormatter.escape(message);
|
||||||
|
lines.add(String.format(large ? " %s " : " %s ", message));
|
||||||
|
len = Math.max(length(message) + (large ? 4 : 2), len);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]]></code>
|
||||||
|
</test-code>
|
||||||
</test-data>
|
</test-data>
|
||||||
|
Reference in New Issue
Block a user