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

StringBuilder.toString allocation for the empty String

    XMLWordPrintable

Details

    • b11
    • generic
    • generic

    Backports

      Description

        A DESCRIPTION OF THE PROBLEM :
        In Java 17 StringBuilder.toString was calling StringLatin1.newString that returned a literal "" for len == 0. After https://bugs.openjdk.org/browse/JDK-8282429 https://github.com/openjdk/jdk/commit/bab431cc120fe09be371dadef0c1caf79ec9eef4 Java 21 returns a new String object each time. While it is minor, it still looks like a regression that effects such code paths as deserialisation.

        REGRESSION : Last worked in version 17.0.10

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        new StringBuilder().toString() == ""

        ACTUAL -
        false

        ---------- BEGIN SOURCE ----------
        public class Test {
            public static void main(String[] args) {
                System.out.println(new StringBuilder().toString() == "");
            }
        }
        ---------- END SOURCE ----------

        FREQUENCY : always


        Attachments

          Issue Links

            Activity

              People

                redestad Claes Redestad
                webbuggrp Webbug Group
                Votes:
                0 Vote for this issue
                Watchers:
                10 Start watching this issue

                Dates

                  Created:
                  Updated:
                  Resolved: