Add test case for #2595

This commit is contained in:
Clément Fournier
2020-11-11 15:33:38 +01:00
parent 154f9387b2
commit a5c42ddefc

View File

@ -698,4 +698,33 @@ public class Foo {
}
]]></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>