diff --git a/src/java.base/share/classes/java/util/regex/Pattern.java b/src/java.base/share/classes/java/util/regex/Pattern.java index 972697fcb0f..898cfb2135c 100644 --- a/src/java.base/share/classes/java/util/regex/Pattern.java +++ b/src/java.base/share/classes/java/util/regex/Pattern.java @@ -782,12 +782,9 @@ public final class Pattern * arguments, they can also be passed as inline modifiers. * For example, the following statements have the same effect. *
-     * RegExp r1 = RegExp.compile("abc", Pattern.I|Pattern.M);
-     * RegExp r2 = RegExp.compile("(?im)abc", 0);
+     * Pattern p1 = Pattern.compile("abc", Pattern.CASE_INSENSITIVE|Pattern.MULTILINE);
+     * Pattern p2 = Pattern.compile("(?im)abc", 0);
      * 
- * - * The flags are duplicated so that the familiar Perl match flag - * names are available. */ /** @@ -2527,7 +2524,7 @@ loop: for(int x=0, offset=0; x does not exit"); + throw error("named capturing group <" + name + "> does not exist"); if (create) { hasGroupRef = true; if (has(CASE_INSENSITIVE)) @@ -2922,13 +2919,11 @@ loop: for(int x=0, offset=0; x'"); return sb.toString(); @@ -2974,7 +2969,7 @@ loop: for(int x=0, offset=0; x)", + "\\k<" + groupName + ">")) { + try { + Pattern.compile(pat); + failCount++; + } catch (PatternSyntaxException e) { + if (!e.getMessage().startsWith( + "capturing group name does not start with a" + + " Latin letter")) { + failCount++; + } + } + } + } + // Invalid char in a group name + for (String groupName : List.of("a.", "b\u0040", "c\u005b", + "d\u0060", "e\u007b", "f\u0416")) { + for (String pat : List.of("(?<" + groupName + ">)", + "\\k<" + groupName + ">")) { + try { + Pattern.compile(pat); + failCount++; + } catch (PatternSyntaxException e) { + if (!e.getMessage().startsWith( + "named capturing group is missing trailing '>'")) { + failCount++; + } + } + } + } + report("Invalid capturing group names"); + } }