From 6fd4d7aaa8d9c487a8b95e785257e7494a525711 Mon Sep 17 00:00:00 2001 From: Nadya Zabrodina Date: Wed, 1 Mar 2017 17:24:02 +0300 Subject: [PATCH] [ignored]: fix thread safety by replacing Matcher.reset to new instance * fix StringIndexOutOfBoundsException from (CPP-8843); * remember compiled Pattern instead of Matcher; * problem was introduced in c1180cfb7f89 --- .../openapi/vcs/changes/IgnoredFileBean.java | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/platform/vcs-api/src/com/intellij/openapi/vcs/changes/IgnoredFileBean.java b/platform/vcs-api/src/com/intellij/openapi/vcs/changes/IgnoredFileBean.java index ad302067592f..a1346ec645c5 100644 --- a/platform/vcs-api/src/com/intellij/openapi/vcs/changes/IgnoredFileBean.java +++ b/platform/vcs-api/src/com/intellij/openapi/vcs/changes/IgnoredFileBean.java @@ -34,13 +34,13 @@ import com.intellij.util.PathUtilRt; import com.intellij.util.PatternUtil; import org.jetbrains.annotations.Nullable; -import java.util.regex.Matcher; +import java.util.regex.Pattern; public class IgnoredFileBean { private final String myPath; private final String myFilenameIfFile; private final String myMask; - private final Matcher myMatcher; + @Nullable private final Pattern myPattern; private final IgnoreSettingsType myType; private final Project myProject; private volatile VirtualFile myCachedResolved; @@ -51,7 +51,7 @@ public class IgnoredFileBean { myFilenameIfFile = IgnoreSettingsType.FILE.equals(type) ? PathUtilRt.getFileName(path) : null; myProject = project; myMask = null; - myMatcher = null; + myPattern = null; } Project getProject() { @@ -61,12 +61,7 @@ public class IgnoredFileBean { IgnoredFileBean(String mask) { myType = IgnoreSettingsType.MASK; myMask = mask; - if (mask == null) { - myMatcher = null; - } - else { - myMatcher = PatternUtil.fromMask(mask).matcher(""); - } + myPattern = mask != null ? PatternUtil.fromMask(mask) : null; myPath = null; myFilenameIfFile = null; myProject = null; @@ -110,8 +105,7 @@ public class IgnoredFileBean { public boolean matchesFile(VirtualFile file) { if (myType == IgnoreSettingsType.MASK) { - myMatcher.reset(file.getName()); - return myMatcher.matches(); + return myPattern != null && myPattern.matcher(file.getName()).matches(); } else { // quick check for 'file' == exact match pattern