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

StringJoiner does not handle too large strings correctly

    XMLWordPrintable

Details

    • b27

    Description

      A DESCRIPTION OF THE PROBLEM :
      StringJoiner does not handle or detect when too large strings are joined or built. This can result in NegativeArraySizeException and possibly other incorrect behavior.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the code provided below.
      Requirements:
      - String.COMPACT_STRINGS = true (probably the default)
      - JVM arg -Xmx3G

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      RuntimeException or OutOfMemoryError is thrown during building because result would be too large.
      ACTUAL -
      NegativeArraySizeException is thrown.

      ---------- BEGIN SOURCE ----------
      // To not get OutOfMemoryError because JVM cannot create that large arrays
      int missingToMaxInt = 10;

      // Requires String.COMPACT_STRINGS = true and -Xmx3G
      new StringJoiner("")
          .add("a".repeat(Integer.MAX_VALUE - missingToMaxInt))
          .add("a".repeat(missingToMaxInt + 1))
          .toString();
      ---------- END SOURCE ----------

      Attachments

        Issue Links

          Activity

            People

              jlaskey Jim Laskey (Inactive)
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: