Menu

#911 False positive in UseStringBufferForStringAppends

open
pmd (543)
5
2014-12-20
2010-01-05
No

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.

Discussion

  • Susan Hoover

    Susan Hoover - 2010-01-05

    example code for false positive

     
  • Susan Hoover

    Susan Hoover - 2010-01-05

    Usage of sample code:

    $java UseStringBufferForStringAppendsTest "foo: 1, 2, 3, 4, 6"
    Left: foo
    Right:
    1
    2
    3
    4
    6
    --- end of list

     
  • Raphael Corre

    Raphael Corre - 2010-04-26

    I have experienced the same issue using the following code :

    String[] tab;
    tab = java.util.Arrays.copyOf(tab, newLength);

     

Log in to post a comment.