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

Pattern.compile() can throw confusing NegativeArraySizeException

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 13
    • Component/s: core-libs
    • Labels:
    • Subcomponent:
    • Resolved In Build:
      b20
    • Verification:
      Verified

      Description

      Due to numerical overflow the following code throws NegativeArraySizeException instead of OutOfMemoryError:

      import java.util.regex.*;

      public class T {
          public static void main(String[] args) throws Throwable {
              Pattern.compile("\\Q" + "a".repeat(Integer.MAX_VALUE / 3 + 42));
          }
      }

      The test requires extra memory to hold a large pattern, so it needs to be run with -Xmx5G at least.

        Attachments

          Activity

            People

            • Assignee:
              igerasim Ivan Gerasimov
              Reporter:
              igerasim Ivan Gerasimov
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: