False positive in UseStringBufferForStringAppends
A source code analyzer
Brought to you by:
adangel,
juansotuyo
Using PMD 4.2.5, we have encountered a case where PMD seems to be issuing a false positive for UseStringBufferForStringAppends. The case is where we are assigning the result of a method call on a String in a String[] back to the String[]. Something like:
String[] tokens = input.split(COLON_SEPARATOR);
...
tokens = tokens[1].split(COMMA_SEPARATOR); // UseStringBufferForStringAppends is reported for this line
Full working sample code is in the attached file.
Yes, this is an ugly DD anomaly sort of thing, but regardless, I think it should not be reporting UseStringBufferForStringAppends. In our environment, UseStringBufferForStringAppends is priority 3, but DD anomaly is only priority 5.
example code for false positive
Usage of sample code:
$java UseStringBufferForStringAppendsTest "foo: 1, 2, 3, 4, 6"
Left: foo
Right:
1
2
3
4
6
--- end of list
I have experienced the same issue using the following code :
String[] tab;
tab = java.util.Arrays.copyOf(tab, newLength);