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
This commit is contained in:
peter
2017-11-07 14:19:03 +01:00
parent 2ffef332bd
commit b42b24f0a6
3 changed files with 7 additions and 2 deletions
@@ -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();
/**
@@ -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;
@@ -75,7 +75,7 @@ public class RootIndex {
myProject = project;
myInfoCache = cache;
ApplicationManager.getApplication().isReadAccessAllowed();
ApplicationManager.getApplication().assertReadAccessAllowed();
final RootInfo info = buildRootInfo(project);