PMD 4.0
Sun JDK 6u2
public class Test
{
private static void foo(String s)
{
return s;
}
public static void main(String[] args)
throws Exception
{
String hdr = args[0];
int pos = hdr.indexOf(';');
hdr = ((pos == -1) ? hdr : hdr.substring(0, pos)).trim();
hdr = foo(hdr);
}
}
$ pmd-4.0/bin/pmd.bat Test.java text optimizations
C:\cygwin\tmp__PMD_\Test.java:3 Parameter 's' is not assigned and could be declared final
C:\cygwin\tmp__PMD_\Test.java:8 Parameter 'args' is not assigned and could be declared final
C:\cygwin\tmp__PMD_\Test.java:12 Local variable 'pos' could be declared final
C:\cygwin\tmp__PMD_\Test.java:14 Prefer StringBuffer over += for concatenating strings
C:\cygwin\tmp__PMD_\Test.java:15 Prefer StringBuffer over += for concatenating strings
It looks like the StringBuffer rule is falsely triggered because hdr is a String and appears twice in the same statement.
I'll investigate and try to reproduce this bug. Thanks for the report.