changeset 12397:dbf817e78280 jdk8u152-b02

8169056: StringIndexOutOfBoundsException in Pattern.compile with CANON_EQ flag Reviewed-by: coffeys
author igerasim
date Thu, 23 Mar 2017 11:48:23 -0700
parents cc7f20a9beb2
children 80280d8b40e9 98d941f5c8cc
files src/share/classes/java/util/regex/Pattern.java test/java/util/regex/RegExTest.java
diffstat 2 files changed, 13 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/java/util/regex/Pattern.java	Thu Mar 23 08:41:32 2017 -0700
+++ b/src/share/classes/java/util/regex/Pattern.java	Thu Mar 23 11:48:23 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2017, 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
@@ -1411,6 +1411,8 @@
         String result;
 
         i++;
+        if (i == normalizedPattern.length())
+            throw error("Unclosed character class");
         charClass.append("[");
         while(true) {
             int c = normalizedPattern.codePointAt(i);
--- a/test/java/util/regex/RegExTest.java	Thu Mar 23 08:41:32 2017 -0700
+++ b/test/java/util/regex/RegExTest.java	Thu Mar 23 11:48:23 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2017, 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
@@ -32,7 +32,7 @@
  * 6358731 6178785 6284152 6231989 6497148 6486934 6233084 6504326 6635133
  * 6350801 6676425 6878475 6919132 6931676 6948903 6990617 7014645 7039066
  * 7067045 7014640 7189363 8007395 8013252 8013254 8012646 8023647 6559590
- * 8027645 6854417
+ * 8027645 6854417 8169056
  */
 
 import java.util.regex.*;
@@ -2144,6 +2144,14 @@
         if (!pattern.matcher("\u017f\u0130\u0131\u212a\u212b").matches())
             failCount++;
 
+        try {
+            Pattern.compile("[", Pattern.CANON_EQ);
+            failCount++;
+        } catch (PatternSyntaxException expected) {
+        } catch (Exception unexpected) {
+            failCount++;
+        }
+
         report("CharClass");
     }