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

StringBuilder / StringBuffer capacity() doc is misleading

    XMLWordPrintable

Details

    • CSR
    • Resolution: Approved
    • P3
    • 14
    • core-libs
    • None
    • minimal
    • Clarification of existing API. No change in behaviour.
    • Java API
    • SE

    Description

      Summary

      The proposed change clarifies that the result from StringBuilder::capacity and StringBuffer::capacity to mean total available space and not just the space available for new characters,

      Problem

      The current description implies that capacity is space available for new or additional characters. Capacity is the space available in total.

      Solution

      Update the javadoc to clarify.

      Specification

      diff --git a/src/java.base/share/classes/java/lang/AbstractStringBuilder.java b/src/java.base/share/classes/java/lang/AbstractStringBuilder.java
      --- a/src/java.base/share/classes/java/lang/AbstractStringBuilder.java
      +++ b/src/java.base/share/classes/java/lang/AbstractStringBuilder.java
      @@ -181,9 +181,9 @@
           }
      
           /**
      -     * Returns the current capacity. The capacity is the amount of storage
      -     * available for newly inserted characters, beyond which an allocation
      -     * will occur.
      +     * Returns the current capacity. The capacity is the number of characters
      +     * that can be stored (including already written characters), beyond which
      +     * an allocation will occur.
            *
            * @return  the current capacity
            */

      Attachments

        Issue Links

          Activity

            People

              jlaskey Jim Laskey
              webbuggrp Webbug Group
              Brent Christian
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: