From b42b24f0a60187f01803024a6aa8f31777fcba46 Mon Sep 17 00:00:00 2001 From: peter Date: Tue, 7 Nov 2017 14:19:03 +0100 Subject: [PATCH] really assert that directory index is initialized inside a read action otherwise roots can become invalid during its creation and be cached so also fix one offender and add contracts to prevent similar assert/is typos in future --- .../src/com/intellij/openapi/application/Application.java | 4 ++++ .../src/com/intellij/util/indexing/FileBasedIndex.java | 3 ++- .../src/com/intellij/openapi/roots/impl/RootIndex.java | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/platform/core-api/src/com/intellij/openapi/application/Application.java b/platform/core-api/src/com/intellij/openapi/application/Application.java index a914ffb4a1ab..48789d8435d2 100644 --- a/platform/core-api/src/com/intellij/openapi/application/Application.java +++ b/platform/core-api/src/com/intellij/openapi/application/Application.java @@ -22,6 +22,7 @@ import com.intellij.openapi.util.Computable; import com.intellij.openapi.util.Condition; import com.intellij.openapi.util.ThrowableComputable; import com.intellij.util.ThrowableRunnable; +import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; import java.awt.*; @@ -166,6 +167,7 @@ public interface Application extends ComponentManager { * @see #assertWriteAccessAllowed() * @see #runWriteAction(Runnable) */ + @Contract(pure=true) boolean isWriteAccessAllowed(); /** @@ -175,6 +177,7 @@ public interface Application extends ComponentManager { * @see #assertReadAccessAllowed() * @see #runReadAction(Runnable) */ + @Contract(pure=true) boolean isReadAccessAllowed(); /** @@ -182,6 +185,7 @@ public interface Application extends ComponentManager { * * @return true if the current thread is the Swing dispatch thread, false otherwise. */ + @Contract(pure=true) boolean isDispatchThread(); /** diff --git a/platform/indexing-api/src/com/intellij/util/indexing/FileBasedIndex.java b/platform/indexing-api/src/com/intellij/util/indexing/FileBasedIndex.java index e10303de7e47..0e186466cac6 100644 --- a/platform/indexing-api/src/com/intellij/util/indexing/FileBasedIndex.java +++ b/platform/indexing-api/src/com/intellij/util/indexing/FileBasedIndex.java @@ -16,6 +16,7 @@ package com.intellij.util.indexing; import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.application.ReadAction; import com.intellij.openapi.fileTypes.FileType; import com.intellij.openapi.progress.ProgressIndicator; import com.intellij.openapi.project.Project; @@ -168,7 +169,7 @@ public abstract class FileBasedIndex { if (visitedRoots != null && !root.equals(file) && file.isDirectory() && !visitedRoots.add(file)) { return false; } - if (projectFileIndex != null && projectFileIndex.isExcluded(file)) { + if (projectFileIndex != null && ReadAction.compute(() -> projectFileIndex.isExcluded(file))) { return false; } return true; diff --git a/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/RootIndex.java b/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/RootIndex.java index 4bfdc944b17d..01b72cb49144 100644 --- a/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/RootIndex.java +++ b/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/RootIndex.java @@ -75,7 +75,7 @@ public class RootIndex { myProject = project; myInfoCache = cache; - ApplicationManager.getApplication().isReadAccessAllowed(); + ApplicationManager.getApplication().assertReadAccessAllowed(); final RootInfo info = buildRootInfo(project);