Menu

#1177 Incorrect StringBuffer warning when that class is not used

PMD-5.1.1
closed
None
PMD
4-Minor
Bug
5.1.0
2014-04-27
2014-03-31
No

The following code when checked with "-R java-strings", gives a warning about StringBuffer despite no StringBuffer being used at all in the code. This first appeared when I updated from 5.0.5 to 5.1.0.

    public class Ineffecient
    {
        public static String getValue(int in)
        {
            Integer i = new Integer(in);
            if (i.toString().length() == 1)
            {
                return "length 1";
            }
            return "";
        }

        public String toString()
        {
            return "Ineffecient";
        }
    }

The exact warning is:

 Inefficient.java:6:    This is an inefficient use of StringBuffer.toString; call StringBuffer.length instead.

Removing the class's toString method also means there is no warning, perhaps that is related to the problem.

Discussion

  • Andreas Dangel

    Andreas Dangel - 2014-04-04
    • status: open --> closed
    • assigned_to: Andreas Dangel
    • Milestone: New Tickets --> PMD-Next
     
  • Andreas Dangel

    Andreas Dangel - 2014-04-04

    Will be fixed with the next release.

     

Log in to post a comment.