diff --git a/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndexImpl.java b/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndexImpl.java index ceb9b1a778c2..a613026cf7d4 100644 --- a/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndexImpl.java +++ b/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndexImpl.java @@ -2025,70 +2025,72 @@ public class FileBasedIndexImpl extends FileBasedIndex implements BaseComponent, @Override public boolean processFile(@NotNull final VirtualFile file) { - if (!file.isValid()) { - return true; - } - if (file instanceof VirtualFileSystemEntry && ((VirtualFileSystemEntry)file).isFileIndexed()) { - return true; - } + try (AccessToken ignore = ReadAction.start()) { + if (!file.isValid()) { + return true; + } + if (file instanceof VirtualFileSystemEntry && ((VirtualFileSystemEntry)file).isFileIndexed()) { + return true; + } - if (!(file instanceof VirtualFileWithId)) { - return true; - } - myFileTypeManager.freezeFileTypeTemporarilyIn(file, () -> { - boolean oldStuff = true; - if (file.isDirectory() || !isTooLarge(file)) { - final List> affectedIndexCandidates = getAffectedIndexCandidates(file); - //noinspection ForLoopReplaceableByForEach - for (int i = 0, size = affectedIndexCandidates.size(); i < size; ++i) { - final ID indexId = affectedIndexCandidates.get(i); - try { - if (needsFileContentLoading(indexId) && shouldIndexFile(file, indexId)) { - if (myDoTraceForFilesToBeIndexed) { - LOG.info("Scheduling indexing of " + file + " by request of index " + indexId); + if (!(file instanceof VirtualFileWithId)) { + return true; + } + myFileTypeManager.freezeFileTypeTemporarilyIn(file, () -> { + boolean oldStuff = true; + if (file.isDirectory() || !isTooLarge(file)) { + final List> affectedIndexCandidates = getAffectedIndexCandidates(file); + //noinspection ForLoopReplaceableByForEach + for (int i = 0, size = affectedIndexCandidates.size(); i < size; ++i) { + final ID indexId = affectedIndexCandidates.get(i); + try { + if (needsFileContentLoading(indexId) && shouldIndexFile(file, indexId)) { + if (myDoTraceForFilesToBeIndexed) { + LOG.info("Scheduling indexing of " + file + " by request of index " + indexId); + } + synchronized (myFiles) { + myFiles.add(file); + } + oldStuff = false; + break; } - synchronized (myFiles) { - myFiles.add(file); + } + catch (RuntimeException e) { + final Throwable cause = e.getCause(); + if (cause instanceof IOException || cause instanceof StorageException) { + LOG.info(e); + requestRebuild(indexId); + } + else { + throw e; } - oldStuff = false; - break; - } - } - catch (RuntimeException e) { - final Throwable cause = e.getCause(); - if (cause instanceof IOException || cause instanceof StorageException) { - LOG.info(e); - requestRebuild(indexId); - } - else { - throw e; } } } - } - FileContent fileContent = null; - int inputId = Math.abs(getIdMaskingNonIdBasedFile(file)); - for (ID indexId : myNotRequiringContentIndices) { - if (shouldIndexFile(file, indexId)) { - oldStuff = false; - if (fileContent == null) { - fileContent = new FileContentImpl(file); + FileContent fileContent = null; + int inputId = Math.abs(getIdMaskingNonIdBasedFile(file)); + for (ID indexId : myNotRequiringContentIndices) { + if (shouldIndexFile(file, indexId)) { + oldStuff = false; + if (fileContent == null) { + fileContent = new FileContentImpl(file); + } + updateSingleIndex(indexId, file, inputId, fileContent); } - updateSingleIndex(indexId, file, inputId, fileContent); } - } - IndexingStamp.flushCache(inputId); + IndexingStamp.flushCache(inputId); - if (oldStuff && file instanceof VirtualFileSystemEntry) { - ((VirtualFileSystemEntry)file).setFileIndexed(true); - } - }); + if (oldStuff && file instanceof VirtualFileSystemEntry) { + ((VirtualFileSystemEntry)file).setFileIndexed(true); + } + }); - if (myProgressIndicator != null && file.isDirectory()) { // once for dir is cheap enough - myProgressIndicator.checkCanceled(); - myProgressIndicator.setText("Scanning files to index"); + if (myProgressIndicator != null && file.isDirectory()) { // once for dir is cheap enough + myProgressIndicator.checkCanceled(); + myProgressIndicator.setText("Scanning files to index"); + } + return true; } - return true; } } diff --git a/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndexScanRunnableCollectorImpl.java b/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndexScanRunnableCollectorImpl.java index f6c87f0e5e29..29287e92245c 100644 --- a/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndexScanRunnableCollectorImpl.java +++ b/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndexScanRunnableCollectorImpl.java @@ -16,7 +16,6 @@ package com.intellij.util.indexing; import com.intellij.openapi.application.AccessToken; -import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.ReadAction; import com.intellij.openapi.extensions.Extensions; import com.intellij.openapi.fileTypes.FileTypeManager; @@ -126,10 +125,6 @@ public class FileBasedIndexScanRunnableCollectorImpl extends FileBasedIndexScanR } } - for(int i = 0, size = tasks.size(); i < size; ++i) { - Runnable runnable = tasks.get(i); - tasks.set(i, () -> ApplicationManager.getApplication().runReadAction(runnable)); - } return tasks; } }