diff --git a/java/compiler/impl/src/com/intellij/compiler/backwardRefs/CompilerReferenceServiceImpl.java b/java/compiler/impl/src/com/intellij/compiler/backwardRefs/CompilerReferenceServiceImpl.java index 43975a3c67a1..bba107fcd03f 100644 --- a/java/compiler/impl/src/com/intellij/compiler/backwardRefs/CompilerReferenceServiceImpl.java +++ b/java/compiler/impl/src/com/intellij/compiler/backwardRefs/CompilerReferenceServiceImpl.java @@ -23,6 +23,7 @@ import com.intellij.lang.injection.InjectedLanguageManager; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.ReadAction; import com.intellij.openapi.compiler.*; +import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.fileEditor.FileDocumentManager; import com.intellij.openapi.fileTypes.FileType; import com.intellij.openapi.module.Module; @@ -63,6 +64,8 @@ import static com.intellij.psi.search.GlobalSearchScope.getScopeRestrictedByFile import static com.intellij.psi.search.GlobalSearchScope.notScope; public class CompilerReferenceServiceImpl extends CompilerReferenceService implements ModificationTracker { + private final static Logger LOG = Logger.getInstance(CompilerReferenceServiceImpl.class); + private final Set myFileTypes; private final DirtyModulesHolder myDirtyModulesHolder; private final ProjectFileIndex myProjectFileIndex; @@ -169,10 +172,16 @@ public class CompilerReferenceServiceImpl extends CompilerReferenceService imple public GlobalSearchScope getScopeWithoutCodeReferences(@NotNull PsiElement element) { if (!isServiceEnabledFor(element)) return null; - return CachedValuesManager.getCachedValue(element, - () -> CachedValueProvider.Result.create(calculateScopeWithoutReferences(element), - PsiModificationTracker.MODIFICATION_COUNT, - this)); + try { + return CachedValuesManager.getCachedValue(element, + () -> CachedValueProvider.Result.create(calculateScopeWithoutReferences(element), + PsiModificationTracker.MODIFICATION_COUNT, + this)); + } + catch (Exception e) { + LOG.error("an exception during scope without code references calculation", e); + return null; + } } @Nullable @@ -201,27 +210,34 @@ public class CompilerReferenceServiceImpl extends CompilerReferenceService imple @NotNull CompilerHierarchySearchType searchType) { if (!isServiceEnabledFor(aClass) || searchScope == LibraryScopeCache.getInstance(myProject).getLibrariesOnlyScope()) return null; - Map candidatesPerFile = ReadAction.compute(() -> { - if (myProject.isDisposed()) throw new ProcessCanceledException(); - return CachedValuesManager.getCachedValue(aClass, () -> CachedValueProvider.Result.create( - new ConcurrentFactoryMap>() { - @Nullable - @Override - protected Map create(HierarchySearchKey key) { - return calculateDirectInheritors(aClass, - useScope, - key.mySearchFileType, - key.mySearchType); - } - }, PsiModificationTracker.MODIFICATION_COUNT, this)).get(new HierarchySearchKey(searchType, searchFileType)); - }); + try { - if (candidatesPerFile == null) return null; - GlobalSearchScope dirtyScope = myDirtyModulesHolder.getDirtyScope(); - if (ElementPlace.LIB == ReadAction.compute(() -> ElementPlace.get(aClass.getContainingFile().getVirtualFile(), myProjectFileIndex))) { - dirtyScope = dirtyScope.union(LibraryScopeCache.getInstance(myProject).getLibrariesOnlyScope()); + Map candidatesPerFile = ReadAction.compute(() -> { + if (myProject.isDisposed()) throw new ProcessCanceledException(); + return CachedValuesManager.getCachedValue(aClass, () -> CachedValueProvider.Result.create( + new ConcurrentFactoryMap>() { + @Nullable + @Override + protected Map create(HierarchySearchKey key) { + return calculateDirectInheritors(aClass, + useScope, + key.mySearchFileType, + key.mySearchType); + } + }, PsiModificationTracker.MODIFICATION_COUNT, this)).get(new HierarchySearchKey(searchType, searchFileType)); + }); + + if (candidatesPerFile == null) return null; + GlobalSearchScope dirtyScope = myDirtyModulesHolder.getDirtyScope(); + if (ElementPlace.LIB == ReadAction.compute(() -> ElementPlace.get(aClass.getContainingFile().getVirtualFile(), myProjectFileIndex))) { + dirtyScope = dirtyScope.union(LibraryScopeCache.getInstance(myProject).getLibrariesOnlyScope()); + } + return new CompilerHierarchyInfoImpl(candidatesPerFile, aClass, dirtyScope, searchScope, myProject, searchFileType, searchType); + } + catch (Exception e) { + LOG.error("an exception during hierarchy calculation", e); + return null; } - return new CompilerHierarchyInfoImpl(candidatesPerFile, aClass, dirtyScope, searchScope, myProject, searchFileType, searchType); } private boolean isServiceEnabledFor(PsiElement element) {