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

(spec str) StringBuffer and StringBuilder methods improperly require "new" String to be returned

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: P4
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: tbd
    • Component/s: core-libs
    • Labels:
      None

      Description

      Several methods in StringBuilder and StringBuffer return String objects. Their specifications require creation of new String objects even though this is unnecessary in some circumstances. Such methods include:

        substring(int)
        substring(int, int)
        subSequence(int, int)
        toString()

      in both StringBuffer and StringBuilder.

      The specs of the corresponding methods in String were clarified by JDK-7174936, and the spec of the CharSequence.subSequence method was clarified by JDK-8028757.

      An example where a new String object need not be created might be if the result of calling toString() were cached, so that subsequent calls to toString() might return the same String. Another example would be returning "" (the empty string literal) if a substring has zero length.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              smarks Stuart Marks
              Reporter:
              smarks Stuart Marks
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated: