Menu

#1371 InsufficientStringBufferDeclaration not detected properly on StringBuffer

PMD-5.3.4
closed
None
PMD
3-Major
Bug
5.3.2
2015-09-04
2015-06-10
No

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());
    }
}

Discussion

  • Andreas Dangel

    Andreas Dangel - 2015-09-04
    • status: open --> closed
    • assigned_to: Andreas Dangel
    • Milestone: New Tickets --> PMD-5.3.4
     

Log in to post a comment.

MongoDB Logo MongoDB