mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
more general solution for EA-109439(wrap regular expr matching in catch)
This commit is contained in:
@@ -15,8 +15,6 @@
|
||||
*/
|
||||
package com.jetbrains.jsonSchema;
|
||||
|
||||
import com.intellij.idea.RareLogger;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.AtomicClearableLazyValue;
|
||||
import com.intellij.openapi.util.io.FileUtilRt;
|
||||
@@ -31,13 +29,14 @@ import com.intellij.util.SmartList;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.xmlb.annotations.Tag;
|
||||
import com.intellij.util.xmlb.annotations.Transient;
|
||||
import com.jetbrains.jsonSchema.impl.JsonSchemaObject;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* @author Irina.Chernushina on 4/19/2017.
|
||||
@@ -49,7 +48,6 @@ public class UserDefinedJsonSchemaConfiguration {
|
||||
if (o1.directory != o2.directory) return o1.directory ? -1 : 1;
|
||||
return o1.path.compareToIgnoreCase(o2.path);
|
||||
};
|
||||
private static final Logger LOG = RareLogger.wrap(Logger.getInstance(UserDefinedJsonSchemaConfiguration.class), false);
|
||||
|
||||
public String name;
|
||||
public String relativePathToSchema;
|
||||
@@ -118,31 +116,25 @@ public class UserDefinedJsonSchemaConfiguration {
|
||||
|
||||
private List<PairProcessor<Project, VirtualFile>> recalculatePatterns() {
|
||||
final List<PairProcessor<Project, VirtualFile>> result = new SmartList<>();
|
||||
for (final Item pattern : patterns) {
|
||||
if (pattern.pattern) {
|
||||
for (final Item patternText : patterns) {
|
||||
if (patternText.pattern) {
|
||||
result.add(new PairProcessor<Project, VirtualFile>() {
|
||||
private final Matcher matcher = PatternUtil.fromMask(pattern.path).matcher("");
|
||||
private final Pattern pattern = PatternUtil.fromMask(patternText.path);
|
||||
|
||||
@Override
|
||||
public boolean process(Project project, VirtualFile file) {
|
||||
matcher.reset(file.getName());
|
||||
try {
|
||||
return matcher.matches();
|
||||
} catch (Exception e) {
|
||||
LOG.info(e);
|
||||
return false;
|
||||
}
|
||||
return JsonSchemaObject.matchPattern(pattern, file.getName());
|
||||
}
|
||||
});
|
||||
}
|
||||
else if (pattern.directory) {
|
||||
else if (patternText.directory) {
|
||||
result.add((project, vfile) -> {
|
||||
final VirtualFile relativeFile = getRelativeFile(project, pattern);
|
||||
final VirtualFile relativeFile = getRelativeFile(project, patternText);
|
||||
return relativeFile != null && VfsUtilCore.isAncestor(relativeFile, vfile, true);
|
||||
});
|
||||
}
|
||||
else {
|
||||
result.add((project, vfile) -> vfile.equals(getRelativeFile(project, pattern)));
|
||||
result.add((project, vfile) -> vfile.equals(getRelativeFile(project, patternText)));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
@@ -178,6 +170,7 @@ public class UserDefinedJsonSchemaConfiguration {
|
||||
: info.relativePathToSchema != null) {
|
||||
return false;
|
||||
}
|
||||
//noinspection RedundantIfStatement
|
||||
if (patterns != null ? !patterns.equals(info.patterns) : info.patterns != null) return false;
|
||||
|
||||
return true;
|
||||
@@ -244,6 +237,7 @@ public class UserDefinedJsonSchemaConfiguration {
|
||||
|
||||
if (pattern != item.pattern) return false;
|
||||
if (directory != item.directory) return false;
|
||||
//noinspection RedundantIfStatement
|
||||
if (path != null ? !path.equals(item.path) : item.path != null) return false;
|
||||
|
||||
return true;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.jetbrains.jsonSchema.impl;
|
||||
|
||||
import com.intellij.json.psi.JsonObject;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.progress.ProcessCanceledException;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
@@ -551,9 +552,7 @@ public class JsonSchemaObject {
|
||||
|
||||
JsonSchemaObject object = (JsonSchemaObject)o;
|
||||
|
||||
if (!myJsonObject.equals(object.myJsonObject)) return false;
|
||||
|
||||
return true;
|
||||
return myJsonObject.equals(object.myJsonObject);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -578,11 +577,16 @@ public class JsonSchemaObject {
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean matchPattern(@NotNull final Pattern pattern, @NotNull final String s) {
|
||||
public static boolean matchPattern(@NotNull final Pattern pattern, @NotNull final String s) {
|
||||
try {
|
||||
return pattern.matcher(StringUtil.newBombedCharSequence(s, 300)).matches();
|
||||
} catch (ProcessCanceledException e) {
|
||||
// something wrong with the pattern
|
||||
// something wrong with the pattern, infinite cycle?
|
||||
return false;
|
||||
} catch (Exception e) {
|
||||
// catch exceptions around to prevent things like:
|
||||
// https://bugs.openjdk.java.net/browse/JDK-6984178
|
||||
Logger.getInstance(JsonSchemaObject.class).info(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user