There is an inconsistent behaviour on InsufficientStringBufferDeclaration, which is not always reported.
The code below is a sample where there are 2 equally wrong uses of StringBuffer but only one is reported.
public class StringBufferTest {
private static String TAG = "TAG";
public void test() {
// this line is not reported as InsufficientStringBufferDeclaration
final StringBuffer stringBuffer = new StringBuffer().append("agrego ").append("un ");
stringBuffer.append("string ");
Log.i(TAG, stringBuffer.toString());
// this line is reported as InsufficientStringBufferDeclaration
final StringBuffer stringBuffer2 = new StringBuffer();
stringBuffer2.append("agrego ");
stringBuffer2.append("un ");
stringBuffer2.append("string ");
Log.i(TAG, stringBuffer2.toString());
}
}
This will be fixed with PMD 5.3.4.
Commit:
See also: https://github.com/pmd/pmd/pull/69