data race when HighlightingSession disposed but HighlightingSessionImpl.myAddHighlighterInEDTQueue didn't apply all its highlighters yet

This commit is contained in:
Alexey Kudravtsev
2016-10-25 13:45:05 +03:00
parent 12c6075874
commit 9b4c2e95bc
2 changed files with 14 additions and 2 deletions
@@ -17,6 +17,7 @@
package com.intellij.codeInsight.daemon.impl;
import com.intellij.codeHighlighting.TextEditorHighlightingPass;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.progress.ProgressIndicator;
@@ -151,8 +152,16 @@ public abstract class ProgressableTextEditorHighlightingPass extends TextEditorH
}
}
void waitForHighlightInfosApplied() {
ApplicationManager.getApplication().assertIsDispatchThread();
HighlightingSessionImpl session = (HighlightingSessionImpl)myHighlightingSession;
if (session != null) {
session.waitForHighlightInfosApplied();
}
}
static class EmptyPass extends TextEditorHighlightingPass {
public EmptyPass(final Project project, @Nullable final Document document) {
EmptyPass(final Project project, @Nullable final Document document) {
super(project, document, false);
}
@@ -517,6 +517,9 @@ class PassExecutorService implements Disposable {
throw new RuntimeException(message, e);
}
if (threadsToStartCountdown.decrementAndGet() == 0) {
if (pass instanceof ProgressableTextEditorHighlightingPass) {
((ProgressableTextEditorHighlightingPass)pass).waitForHighlightInfosApplied();
}
log(updateProgress, pass, "Stopping ");
updateProgress.stopIfRunning();
}
@@ -543,7 +546,7 @@ class PassExecutorService implements Disposable {
}
private static void sortById(@NotNull List<TextEditorHighlightingPass> result) {
ContainerUtil.quickSort(result, (o1, o2) -> o1.getId() - o2.getId());
ContainerUtil.quickSort(result, Comparator.comparingInt(TextEditorHighlightingPass::getId));
}
private static int getThreadNum() {