8175362: StringIndexOutOfBoundsException from /.*((a[^a]+){2})c$/.exec('ababc')

Reviewed-by: sundar, hannesw
This commit is contained in:
Priya Muthuswamy 2017-08-21 11:33:52 +05:30 committed by Priya Lakshmi Muthuswamy
parent 865f838bf1
commit 4d2272b872
4 changed files with 42 additions and 17 deletions

View File

@ -102,6 +102,8 @@ final class Analyser extends Parser {
env.memNodes = null;
new ArrayCompiler(this).compile();
if (regex.numRepeat != 0 || regex.btMemEnd != 0) {
regex.stackPopLevel = StackPopLevel.ALL;
} else {

View File

@ -127,31 +127,17 @@ public final class Regex implements RegexState {
this.caseFoldFlag = caseFoldFlag;
this.warnings = warnings;
this.analyser = new Analyser(new ScanEnvironment(this, syntax), chars, p, end);
this.analyser.compile();
new Analyser(new ScanEnvironment(this, syntax), chars, p, end).compile();
this.warnings = null;
}
public synchronized MatcherFactory compile() {
if (factory == null && analyser != null) {
new ArrayCompiler(analyser).compile();
analyser = null; // only do this once
}
assert factory != null;
return factory;
}
public Matcher matcher(final char[] chars) {
return matcher(chars, 0, chars.length);
}
public Matcher matcher(final char[] chars, final int p, final int end) {
MatcherFactory matcherFactory = factory;
if (matcherFactory == null) {
matcherFactory = compile();
}
return matcherFactory.create(this, chars, p, end);
return factory.create(this, chars, p, end);
}
public WarnCallback getWarnings() {
@ -309,7 +295,6 @@ public final class Regex implements RegexState {
}
public String dumpByteCode() {
compile();
return new ByteCodePrinter(this).byteCodeListToString();
}

View File

@ -0,0 +1,36 @@
/*
* Copyright (c) 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* JDK-8175362 : StringIndexOutOfBoundsException from /.*((a[^a]+){2})c$/.exec('ababc')
*
* @test
* @run
*/
var regexp;
regexp = new RegExp(".*((a[^a]+){2})c$");
print(regexp.exec("ababc"));
regexp = new RegExp("(a[^a]+){3}");
print(regexp.exec("ababc"));

View File

@ -0,0 +1,2 @@
ababc,abab,ab
null