8023647: "abc1c".matches("(\\w)+1\\1")) returns false
authorsherman
Tue, 27 Aug 2013 12:54:44 -0700
changeset 19604 f96e3aef2081
parent 19603 636cd05ce8e5
child 19605 0f98f8e3bdcb
8023647: "abc1c".matches("(\\w)+1\\1")) returns false Summary: to correct the wrong GroupCurly group index backoff code Reviewed-by: alanb
jdk/src/share/classes/java/util/regex/Pattern.java
jdk/test/java/util/regex/RegExTest.java
--- a/jdk/src/share/classes/java/util/regex/Pattern.java	Mon Aug 26 22:32:50 2013 -0700
+++ b/jdk/src/share/classes/java/util/regex/Pattern.java	Tue Aug 27 12:54:44 2013 -0700
@@ -4456,16 +4456,16 @@
                             groups[groupIndex+1] = i;
                             groups[groupIndex] = i - k;
                         }
-                        i = i - k;
                         return true;
                     }
                     // backing off
+                    i = i - k;
                     if (capture) {
                         groups[groupIndex+1] = i;
                         groups[groupIndex] = i - k;
                     }
-                    i = i - k;
                     j--;
+
                 }
                 break;
             }
@@ -4883,7 +4883,6 @@
             int k = matcher.groups[groupIndex+1];
 
             int groupSize = k - j;
-
             // If the referenced group didn't match, neither can this
             if (j < 0)
                 return false;
@@ -4893,7 +4892,6 @@
                 matcher.hitEnd = true;
                 return false;
             }
-
             // Check each new char to make sure it matches what the group
             // referenced matched last time around
             for (int index=0; index<groupSize; index++)
--- a/jdk/test/java/util/regex/RegExTest.java	Mon Aug 26 22:32:50 2013 -0700
+++ b/jdk/test/java/util/regex/RegExTest.java	Tue Aug 27 12:54:44 2013 -0700
@@ -33,7 +33,7 @@
  * 5013885 5003322 4988891 5098443 5110268 6173522 4829857 5027748 6376940
  * 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
+ * 7067045 7014640 7189363 8007395 8013252 8013254 8012646 8023647
  */
 
 import java.util.regex.*;
@@ -146,6 +146,7 @@
         linebreakTest();
         branchTest();
         groupCurlyNotFoundSuppTest();
+        groupCurlyBackoffTest();
         patternAsPredicate();
         if (failure) {
             throw new
@@ -3999,6 +4000,15 @@
         report("GroupCurly NotFoundSupp");
     }
 
+    // This test is for 8023647
+    private static void groupCurlyBackoffTest() throws Exception {
+        if (!"abc1c".matches("(\\w)+1\\1") ||
+            "abc11".matches("(\\w)+1\\1")) {
+            failCount++;
+        }
+        report("GroupCurly backoff");
+    }
+
     // This test is for 8012646
     private static void patternAsPredicate() throws Exception {
         Predicate<String> p = Pattern.compile("[a-z]+").asPredicate();