mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-20 05:21:29 +07:00
some invalid psi checks (EA-47654, EA-46555)
This commit is contained in:
@@ -32,6 +32,7 @@ import com.intellij.psi.impl.PsiManagerEx;
|
||||
import com.intellij.psi.impl.file.PsiPackageImpl;
|
||||
import com.intellij.psi.impl.java.stubs.index.JavaFullClassNameIndex;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.psi.util.PsiUtilCore;
|
||||
import com.intellij.util.Query;
|
||||
import com.intellij.util.containers.ConcurrentHashMap;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
@@ -138,7 +139,13 @@ public abstract class JavaFileManagerBase implements JavaFileManager, Disposable
|
||||
final String qualifiedName = aClass.getQualifiedName();
|
||||
if (qualifiedName == null || !qualifiedName.equals(qName)) continue;
|
||||
|
||||
VirtualFile vFile = aClass.getContainingFile().getVirtualFile();
|
||||
PsiUtilCore.ensureValid(aClass);
|
||||
PsiFile file = aClass.getContainingFile();
|
||||
if (file == null) {
|
||||
throw new AssertionError("No file for class: " + aClass + " of " + aClass.getClass());
|
||||
}
|
||||
|
||||
VirtualFile vFile = file.getVirtualFile();
|
||||
if (!hasAcceptablePackage(vFile)) continue;
|
||||
|
||||
result.add(aClass);
|
||||
|
||||
@@ -1015,6 +1015,11 @@ public final class PsiUtil extends PsiUtilCore {
|
||||
|
||||
public static void ensureValidType(@NotNull PsiType type) {
|
||||
if (!type.isValid()) {
|
||||
Thread.yield();
|
||||
if (type.isValid()) {
|
||||
LOG.error("PsiType resurrected: " + type + " of " + type.getClass());
|
||||
return;
|
||||
}
|
||||
if (type instanceof PsiClassType) {
|
||||
((PsiClassType)type).resolve(); // should throw exception
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ package com.intellij.psi.util;
|
||||
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.lang.Language;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.util.Key;
|
||||
@@ -38,6 +39,7 @@ import java.util.Collection;
|
||||
* @author yole
|
||||
*/
|
||||
public class PsiUtilCore {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.psi.util.PsiUtilCore");
|
||||
public static final PsiElement NULL_PSI_ELEMENT = new PsiElement() {
|
||||
@Override
|
||||
@NotNull
|
||||
@@ -452,6 +454,11 @@ public class PsiUtilCore {
|
||||
|
||||
public static void ensureValid(@NotNull PsiElement element) {
|
||||
if (!element.isValid()) {
|
||||
Thread.yield();
|
||||
if (element.isValid()) {
|
||||
LOG.error("PSI resurrected: " + element + " of " + element.getClass());
|
||||
return;
|
||||
}
|
||||
throw new PsiInvalidElementAccessException(element);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import com.intellij.psi.impl.source.PsiFileImpl;
|
||||
import com.intellij.psi.impl.source.PsiFileWithStubSupport;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.psi.tree.IStubFileElementType;
|
||||
import com.intellij.psi.util.PsiUtilCore;
|
||||
import com.intellij.util.Processor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -60,11 +61,13 @@ public abstract class StubProcessingHelperBase {
|
||||
final List<StubElement<?>> plained = stubTree.getPlainList();
|
||||
for (int i = 0, size = value.size(); i < size; i++) {
|
||||
final StubElement<?> stub = plained.get(value.get(i));
|
||||
PsiUtilCore.ensureValid(psiFile);
|
||||
final ASTNode tree = psiFile.findTreeForStub(stubTree, stub);
|
||||
|
||||
if (tree != null) {
|
||||
if (tree.getElementType() == stubType(stub)) {
|
||||
Psi psi = (Psi)tree.getPsi();
|
||||
PsiUtilCore.ensureValid(psi);
|
||||
if (!processor.process(psi)) return false;
|
||||
}
|
||||
else {
|
||||
@@ -103,6 +106,7 @@ public abstract class StubProcessingHelperBase {
|
||||
break;
|
||||
}
|
||||
Psi psi = (Psi)plained.get(stubTreeIndex).getPsi();
|
||||
PsiUtilCore.ensureValid(psi);
|
||||
if (!processor.process(psi)) return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user