Fixed issue

This commit is contained in:
John Armgardt
2021-11-12 16:46:36 -06:00
parent f18ceebd7b
commit 2d57e6755a
2 changed files with 22 additions and 1 deletions

View File

@ -54,7 +54,7 @@ public class UselessStringValueOfRule extends AbstractJavaRule {
&& "+".equals(gp.getImage())) {
boolean ok = false;
if (gp.getChild(0) == parent) {
ok = !isPrimitive(gp.getChild(1));
return super.visit(node, data);
} else {
for (int i = 0; !ok && gp.getChild(i) != parent; i++) {
ok = !isPrimitive(gp.getChild(i));

View File

@ -109,6 +109,27 @@ public class Test {
private void print(String s) {
System.out.println(s);
}
}
]]></code>
</test-code>
<test-code>
<description>#3492 False positive for UselessStringValueOf, when there is no initial String to append to</description>
<expected-problems>0</expected-problems>
<code><![CDATA[
public class Test {
private short getPrefix(long id) {
return 0;
}
private short getTimestamp(long id) {
return 0;
}
private short getCounter(long id) {
return 0;
}
public String toShortString(long id) {
return String.valueOf(getPrefix(id)) + getTimestamp(id) + getCounter(id); // (12)
}
}
]]></code>
</test-code>