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

StringJoiner merges with itself not as expected

    XMLWordPrintable

Details

    Description

      Consider the following code:

      import java.util.StringJoiner;

      public class MergeSelf {

          public static void main(String[] args) {
              final StringJoiner joiner1 = new StringJoiner(",", "[", "]").add("a").add("b");
              System.out.println("joiner1.merge(joiner1) = " + joiner1.merge(joiner1));
              System.out.println("joiner1.merge(joiner1) = " + joiner1.merge(joiner1));

              final StringJoiner joiner2 = new StringJoiner(",").add("c").add("d");
              System.out.println("joiner2.merge(joiner2) = " + joiner2.merge(joiner2));
          }
      }

      The output will be:

      joiner1.merge(joiner1) = [a,b,a,b,]
      joiner1.merge(joiner1) = [a,b,a,b,,a,b,a,b,,]
      joiner2.merge(joiner2) = c,d,c,d,


      The following JCK tests will fail due to this issue:

      api/java_util/StringJoiner/index.html#Merge[selfSimple1]
      api/java_util/StringJoiner/index.html#Merge[selfSimple1Delimiter]
      api/java_util/StringJoiner/index.html#Merge[selfSimple2]
      api/java_util/StringJoiner/index.html#Merge[selfSimple2Delimiter]
      api/java_util/StringJoiner/index.html#Merge[selfSimpleTwice1]
      api/java_util/StringJoiner/index.html#Merge[selfSimpleTwice1Delimtier]



      Attachments

        Activity

          People

            henryjen Henry Jen
            dbessono Dmitry Bessonov
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: