changeset 13695:643871d087e0

8222684: Better support for patterns 8223163: Better pattern recognition Reviewed-by: ahgross, bchristi, jeff, rhalade, rriggs, smarks
author igerasim
date Wed, 22 May 2019 19:41:59 -0700
parents 9e42cbb6a9ed
children eeac0c758228
files src/share/classes/java/util/regex/Pattern.java
diffstat 1 files changed, 13 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/java/util/regex/Pattern.java	Tue Apr 30 16:45:29 2019 -0400
+++ b/src/share/classes/java/util/regex/Pattern.java	Wed May 22 19:41:59 2019 -0700
@@ -1348,7 +1348,11 @@
         localCount = 0;
 
         if (pattern.length() > 0) {
-            compile();
+            try {
+                compile();
+            } catch (StackOverflowError soe) {
+                throw error("Stack overflow during pattern compilation");
+            }
         } else {
             root = new Start(lastAccept);
             matchRoot = lastAccept;
@@ -1905,6 +1909,10 @@
         int ch = temp[cursor++];
         while (ch != 0 && !isLineSeparator(ch))
             ch = temp[cursor++];
+        if (ch == 0 && cursor > patternLength) {
+            cursor = patternLength;
+            ch = temp[cursor++];
+        }
         return ch;
     }
 
@@ -1915,6 +1923,10 @@
         int ch = temp[++cursor];
         while (ch != 0 && !isLineSeparator(ch))
             ch = temp[++cursor];
+        if (ch == 0 && cursor > patternLength) {
+            cursor = patternLength;
+            ch = temp[cursor];
+        }
         return ch;
     }