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

StringBuilder / StringBuffer capacity() doc is misleading

    XMLWordPrintable

    Details

    • Type: CSR
    • Status: Closed
    • Priority: P3
    • Resolution: Approved
    • Fix Version/s: 14
    • Component/s: core-libs
    • Labels:
      None
    • Subcomponent:
    • Compatibility Risk:
      minimal
    • Compatibility Risk Description:
      Clarification of existing API. No change in behaviour.
    • Interface Kind:
      Java API
    • Scope:
      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

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

                Dates

                Created:
                Updated:
                Resolved: