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

Pattern.compile() can throw confusing NegativeArraySizeException

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 13
    • None
    • core-libs
    • b20
    • Verified

      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.

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

              Created:
              Updated:
              Resolved: