From e04f0b083fa4b1a3e8f17ad31c2b0e68a9df6a34 Mon Sep 17 00:00:00 2001 From: "Anna.Kozlova" Date: Thu, 17 Nov 2016 11:23:04 +0100 Subject: [PATCH] don't cancel search on ProcessCanceledExceptions from too long regexp processing Caused by: com.intellij.openapi.progress.ProcessCanceledException at com.intellij.openapi.util.text.StringUtil$9.checkCanceled(StringUtil.java:3192) ... at java.util.regex.Matcher.find(Matcher.java:637) at com.intellij.openapi.vcs.IssueNavigationConfiguration.findIssueLinks(IssueNavigationConfiguration.java:98) at com.intellij.psi.impl.source.resolve.reference.ArbitraryPlaceUrlReferenceProvider$1.lambda$compute$0(ArbitraryPlaceUrlReferenceProvider.java:51) --- .../vcs/IssueNavigationConfiguration.java | 32 +++++++++++-------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/platform/vcs-api/src/com/intellij/openapi/vcs/IssueNavigationConfiguration.java b/platform/vcs-api/src/com/intellij/openapi/vcs/IssueNavigationConfiguration.java index b5458fc19353..99e492b5e378 100644 --- a/platform/vcs-api/src/com/intellij/openapi/vcs/IssueNavigationConfiguration.java +++ b/platform/vcs-api/src/com/intellij/openapi/vcs/IssueNavigationConfiguration.java @@ -21,6 +21,7 @@ import com.intellij.openapi.components.PersistentStateComponent; import com.intellij.openapi.components.State; import com.intellij.openapi.components.Storage; import com.intellij.openapi.diagnostic.Logger; +import com.intellij.openapi.progress.ProcessCanceledException; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.SimpleModificationTracker; import com.intellij.openapi.util.TextRange; @@ -92,22 +93,27 @@ public class IssueNavigationConfiguration extends SimpleModificationTracker public List findIssueLinks(CharSequence text) { final List result = new ArrayList<>(); - for (IssueNavigationLink link : myLinks) { - Pattern issuePattern = link.getIssuePattern(); - Matcher m = issuePattern.matcher(text); - while (m.find()) { - try { - String replacement = issuePattern.matcher(m.group(0)).replaceFirst(link.getLinkRegexp()); - addMatch(result, new TextRange(m.start(), m.end()), replacement); - } - catch (Exception e) { - LOG.debug("Malformed regex replacement. IssueLink: " + link + "; text: " + text, e); + try { + for (IssueNavigationLink link : myLinks) { + Pattern issuePattern = link.getIssuePattern(); + Matcher m = issuePattern.matcher(text); + while (m.find()) { + try { + String replacement = issuePattern.matcher(m.group(0)).replaceFirst(link.getLinkRegexp()); + addMatch(result, new TextRange(m.start(), m.end()), replacement); + } + catch (Exception e) { + LOG.debug("Malformed regex replacement. IssueLink: " + link + "; text: " + text, e); + } } } + Matcher m = URLUtil.URL_PATTERN.matcher(text); + while (m.find()) { + addMatch(result, new TextRange(m.start(), m.end()), m.group()); + } } - Matcher m = URLUtil.URL_PATTERN.matcher(text); - while (m.find()) { - addMatch(result, new TextRange(m.start(), m.end()), m.group()); + catch (ProcessCanceledException e) { + //skip too long processing completely } Collections.sort(result); return result; -- 2.23.3