[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 c1180cfb7f
This commit is contained in:
Nadya Zabrodina
2017-03-01 17:34:47 +03:00
parent c942e9e143
commit 6fd4d7aaa8
@@ -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