Skip to content

Commit 8577d3c

Browse files
slavam2605intellij-monorepo-bot
authored andcommitted
[RDCT] IJPL-214110 Fix MarkupModelImpl#addMarkupModelListener for already disposed disposables
GitOrigin-RevId: 05b5ae97a6f1e613081d9c160013062d906ffb1c
1 parent 4de66bd commit 8577d3c

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

platform/editor-ui-ex/src/com/intellij/openapi/editor/impl/MarkupModelImpl.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,10 +217,13 @@ public void removeAllHighlighters() {
217217
public void addMarkupModelListener(@NotNull Disposable parentDisposable, final @NotNull MarkupModelListener listener) {
218218
List<MarkupModelListener> listeners = myListeners;
219219
listeners.add(listener);
220-
Disposer.register(parentDisposable, () -> {
220+
boolean isRegistered = Disposer.tryRegister(parentDisposable, () -> {
221221
boolean success = listeners.remove(listener);
222222
LOG.assertTrue(success);
223223
});
224+
if (!isRegistered) {
225+
listeners.remove(listener);
226+
}
224227
}
225228

226229
@Override

platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/TrafficLightRenderer.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,10 @@ open class TrafficLightRenderer private constructor(
107107
private fun init(project: Project, document: Document) {
108108
val model = DocumentMarkupModel.forDocument(document, project, true) as MarkupModelEx
109109
EdtInvocationManager.invokeLaterIfNeeded(Runnable {
110+
if (isDisposed) return@Runnable
110111
for (rangeHighlighter in model.getAllHighlighters()) {
111112
incErrorCount(rangeHighlighter, 1)
112113
}
113-
if (isDisposed) return@Runnable
114114
model.addMarkupModelListener(this, object : MarkupModelListener {
115115
override fun afterAdded(highlighter: RangeHighlighterEx) {
116116
incErrorCount(highlighter, 1)

0 commit comments

Comments
 (0)