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

Pattern.compile() can throw confusing NegativeArraySizeException

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P3
    • 13
    • None
    • core-libs
    • b20
    • 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

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

            Dates

              Created:
              Updated:
              Resolved: