From b5e3da4d552bdba5a2ad4856bc17ef097181e9c4 Mon Sep 17 00:00:00 2001 From: Eugene Zhuravlev Date: Tue, 30 Apr 2013 14:26:33 +0400 Subject: [PATCH] fixing "dispatch thread assertion": id-to-key index may be created not only on startup, but as a part of certain index rebuild procedure --- .../util/indexing/FileBasedIndexImpl.java | 30 +++++++++++++++---- 1 file changed, 25 insertions(+), 5 deletions(-) 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 e57161d0a3df..54f68c7416d5 100644 --- a/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndexImpl.java +++ b/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndexImpl.java @@ -502,12 +502,32 @@ public class FileBasedIndexImpl extends FileBasedIndex { @Override public PersistentHashMap> create() { try { - return ProgressManager.getInstance().runProcessWithProgressSynchronously(new ThrowableComputable>, IOException>() { - @Override - public PersistentHashMap> compute() throws IOException { - return createIdToDataKeysIndex(indexId, keyDescriptor, storage); + // this factory method may be called either on index creation from dispatch thread, or on index rebuild + // from arbitrary thread and under some existing progress indicator + final ProgressManager progressManager = ProgressManager.getInstance(); + final ProgressIndicator currentProgress = progressManager.getProgressIndicator(); + if (currentProgress == null && ApplicationManager.getApplication().isDispatchThread()) { + return progressManager.runProcessWithProgressSynchronously( + new ThrowableComputable>, IOException>() { + @Override + public PersistentHashMap> compute() throws IOException { + return createIdToDataKeysIndex(indexId, keyDescriptor, storage); + } + }, LangBundle.message("compacting.indices.title"), false, null); + } + if (currentProgress != null) { + // reuse existing progress indicator if available + currentProgress.pushState(); + currentProgress.setText(LangBundle.message("compacting.indices.title")); + } + try { + return createIdToDataKeysIndex(indexId, keyDescriptor, storage); + } + finally { + if (currentProgress != null) { + currentProgress.popState(); } - }, LangBundle.message("compacting.indices.title"), false, null); + } } catch (IOException e) { throw new RuntimeException(e);