< prev index next >

test/jdk/java/util/regex/RegExTest.java

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.

@@ -33,11 +33,11 @@
  * 6350801 6676425 6878475 6919132 6931676 6948903 6990617 7014645 7039066
  * 7067045 7014640 7189363 8007395 8013252 8013254 8012646 8023647 6559590
  * 8027645 8035076 8039124 8035975 8074678 6854417 8143854 8147531 7071819
  * 8151481 4867170 7080302 6728861 6995635 6736245 4916384 6328855 6192895
  * 6345469 6988218 6693451 7006761 8140212 8143282 8158482 8176029 8184706
- * 8194667 8197462 8184692 8221431
+ * 8194667 8197462 8184692 8221431 8224789
  *
  * @library /test/lib
  * @library /lib/testlibrary/java/lang
  * @build jdk.test.lib.RandomFactory
  * @run main RegExTest

@@ -169,10 +169,11 @@
         invalidFlags();
         embeddedFlags();
         grapheme();
         expoBacktracking();
         invalidGroupName();
+        illegalRepetitionRange();
 
         if (failure) {
             throw new
                 RuntimeException("RegExTest failed, 1st failure: " +
                                  firstFailure);

@@ -4930,6 +4931,37 @@
                 }
             }
         }
         report("Invalid capturing group names");
     }
+
+    private static void illegalRepetitionRange() {
+        for (String rep : List.of("", "x", ".", ",", "-1", "2147483648",
+                "4294967296", "4294967297", "9223372032559808512",
+                "18446744073709551615", "420000000000000000000",
+                "4294967296,", "4294967297,", "4294967296,", "4294967297,",
+                "9223372032559808512,", "18446744073709551615,",
+                "420000000000000000000,", "4294967296,4294967296",
+                "4294967296,4294967298", "4294967297,4294967299",
+                "4294967297,42", "9223372032559808514,42",
+                "84467440737095516150123456,84467440737095516150123457",
+                "0,4294967296", "42,4294967397", "1,9223372032559808514",
+                "0,84467440737095515690237952"))
+        {
+            String pat = ".{" + rep + "}";
+            try {
+                Pattern.compile(pat);
+                failCount++;
+                System.out.println("Expected to fail. Pattern: " + pat);
+            } catch (PatternSyntaxException e) {
+                if (!e.getMessage().startsWith("Illegal repetition")) {
+                    failCount++;
+                    System.out.println("Unexpected error message: " + e.getMessage());
+                }
+            } catch (Throwable t) {
+                failCount++;
+                System.out.println("Unexpected exception: " + t);
+            }
+        }
+        report("illegalRepetitionRange");
+    }
 }
< prev index next >