Skip to content
Permalink
Browse files
8276694: Pattern trailing unescaped backslash causes internal error
Reviewed-by: jlaskey
  • Loading branch information
Masanori Yano authored and Ian Graves committed Jan 11, 2022
1 parent 36f41cb commit 3aaa0982d8c1735208a331b0097a5aea4a1fef5a
Showing with 12 additions and 1 deletion.
  1. +2 −0 src/java.base/share/classes/java/util/regex/Pattern.java
  2. +10 −1 test/jdk/java/util/regex/RegExTest.java
@@ -1795,6 +1795,8 @@ private void compile() {
if (patternLength != cursor) {
if (peek() == ')') {
throw error("Unmatched closing ')'");
} else if (cursor == patternLength + 1 && temp[patternLength - 1] == '\\') {
throw error("Unescaped trailing backslash");
} else {
throw error("Unexpected internal error");
}
@@ -35,7 +35,7 @@
* 8151481 4867170 7080302 6728861 6995635 6736245 4916384 6328855 6192895
* 6345469 6988218 6693451 7006761 8140212 8143282 8158482 8176029 8184706
* 8194667 8197462 8184692 8221431 8224789 8228352 8230829 8236034 8235812
* 8216332 8214245 8237599 8241055 8247546 8258259 8037397 8269753
* 8216332 8214245 8237599 8241055 8247546 8258259 8037397 8269753 8276694
*
* @library /test/lib
* @library /lib/testlibrary/java/lang
@@ -4538,4 +4538,13 @@ public static void errorMessageCaretIndentation() {
var sep = System.lineSeparator();
assertTrue(e.getMessage().contains(sep + "\t ^"));
}

//This test is for 8276694
@Test
public static void unescapedBackslash() {
String pattern = "\\";
var e = expectThrows(PatternSyntaxException.class, () ->
Pattern.compile(pattern));
assertTrue(e.getMessage().contains("Unescaped trailing backslash"));
}
}

1 comment on commit 3aaa098

@openjdk-notifier
Copy link

@openjdk-notifier openjdk-notifier bot commented on 3aaa098 Jan 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.