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

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

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • 8, 9
    • core-libs
    • None

      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.

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

              Created:
              Updated: