If SOE encountered when do reg exp matching then ignore the exception and return result (temp fix for IDEA-150928)

This commit is contained in:
Maxim.Mossienko
2017-02-02 18:50:54 +01:00
parent ae422559b4
commit 528b3a1e73
2 changed files with 32 additions and 16 deletions

View File

@@ -909,6 +909,18 @@ public class FindManagerTest extends DaemonAnalyzerTestCase {
assertTrue(condition.value("makefile"));
}
public void testRegExpSOEWhenMatch() throws InterruptedException {
String text = "package com.intellij.demo;\n" +
"\n";
for(int i = 0; i < 10; ++i) text += text;
FindModel findModel = FindManagerTestUtils.configureFindModel(";((?:\\n|.)*export default )(?:DS.Model)(.extend((?:\\n|.)*assets: DS.attr(?:\\n|.)*});)");
findModel.setRegularExpressions(true);
FindResult findResult = myFindManager.findString(text, 0, findModel, null);
assertTrue(!findResult.isStringFound());
}
public void testRegExpSearchDoesCheckCancelled() throws InterruptedException {
String text = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
FindModel findModel = FindManagerTestUtils.configureFindModel("(x+x+)+y");

View File

@@ -777,25 +777,29 @@ public class FindManagerImpl extends FindManager {
if (matcher == null) {
return NOT_FOUND_RESULT;
}
if (model.isForward()){
if (matcher.find(startOffset)) {
if (matcher.end() <= text.length()) {
return new FindResultImpl(matcher.start(), matcher.end());
try {
if (model.isForward()) {
if (matcher.find(startOffset)) {
if (matcher.end() <= text.length()) {
return new FindResultImpl(matcher.start(), matcher.end());
}
}
}
return NOT_FOUND_RESULT;
}
else {
int start = -1;
int end = -1;
while(matcher.find() && matcher.end() < startOffset){
start = matcher.start();
end = matcher.end();
}
if (start < 0){
return NOT_FOUND_RESULT;
}
return new FindResultImpl(start, end);
else {
int start = -1;
int end = -1;
while (matcher.find() && matcher.end() < startOffset) {
start = matcher.start();
end = matcher.end();
}
if (start < 0) {
return NOT_FOUND_RESULT;
}
return new FindResultImpl(start, end);
}
} catch (StackOverflowError soe) {
return NOT_FOUND_RESULT;
}
}