Affects PMD Version: 6.30.0-SNAPSHOT
Rule: InsufficientStringBufferDeclaration,
ConsecutiveLiteralAppends,
AppendCharacterWithChar
Description:
From #2871 (comment)
Code Sample demonstrating the issue:
public class Foo {
public void a() {
StringBuilder sb = new StringBuilder();
int start = sb.indexOf(" ");
if (start == -1) {
sb.append("Bar");
sb.append(" "); // warning expected: Avoid appending characters as strings in StringBuffer.append.
}
}
public void b() {
StringBuffer sb = new StringBuffer(); // warning expected: StringBuffer constructor is initialized with size 16, but has at least 17 characters appended.
sb.append("test "); // warning expected: StringBuffer (or StringBuilder).append is called 3 consecutive times with literals. Use a single append with a single combined String.
sb.append("test2 ").append("test3 ");
}
}
Expected outcome:
- Is PMD missing to report a violation, where there should be one? -> false-negative
Running PMD through: regression-tester
Affects PMD Version: 6.30.0-SNAPSHOT
Rule: InsufficientStringBufferDeclaration,
ConsecutiveLiteralAppends,
AppendCharacterWithChar
Description:
From #2871 (comment)
Code Sample demonstrating the issue:
Expected outcome:
Running PMD through: regression-tester