Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6436304

StringBuffers should be created with appropriate sizes

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P5
    • Resolution: Won't Fix
    • Affects Version/s: 6
    • Fix Version/s: None
    • Component/s: other-libs
    • Labels:
      None

      Description

      j2se/src/share/classes/java/awt/datatransfer/MimeTypeParameterList.java
      j2se/src/share/classes/javax/activation/MimeTypeParameterList.java
      j2se/src/share/classes/com/sun/activation/registries/MailcapTokenizer.java

      all contain code that create default-sized StringBuffers and then immediately resize the buffer appropriately. It would be better if the StringBuffer were created with the appropriate size.

      When someone is in fixing

          4945824: Should consider using StringBuilder instead of String/StringBuffer in AWT

      they should look around for constructors that are followed by calls to ensureCapacity. Here are the calls that I found in the above files

          java/awt/datatransfer/MimeTypeParameterList.java:262: StringBuffer buffer = new StringBuffer();
          java/awt/datatransfer/MimeTypeParameterList.java:263: buffer.ensureCapacity(parameters.size() * 16);
          java/awt/datatransfer/MimeTypeParameterList.java:334: StringBuffer buffer = new StringBuffer();
          java/awt/datatransfer/MimeTypeParameterList.java:335: buffer.ensureCapacity((int)(length * 1.5));
          java/awt/datatransfer/MimeTypeParameterList.java:365: StringBuffer buffer = new StringBuffer();
          java/awt/datatransfer/MimeTypeParameterList.java:366: buffer.ensureCapacity(valueLength);
          javax/activation/MimeTypeParameterList.java:226: StringBuffer buffer = new StringBuffer();
          javax/activation/MimeTypeParameterList.java:227: buffer.ensureCapacity(parameters.size() * 16);
          javax/activation/MimeTypeParameterList.java:275: StringBuffer buffer = new StringBuffer();
          javax/activation/MimeTypeParameterList.java:276: buffer.ensureCapacity((int)(length * 1.5));
          javax/activation/MimeTypeParameterList.java:304: StringBuffer buffer = new StringBuffer();
          javax/activation/MimeTypeParameterList.java:305: buffer.ensureCapacity(valueLength);
          com/sun/activation/registries/MailcapTokenizer.java:256: StringBuffer buffer = new StringBuffer();
          com/sun/activation/registries/MailcapTokenizer.java:257: buffer.ensureCapacity(inputLength);

      I'm filing this under classes_awt. If that's the wrong subcategory, feel free to recategorize this.

        Attachments

          Activity

            People

            Assignee:
            bshannon Bill Shannon (Inactive)
            Reporter:
            pbk Peter Kessler
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: