Skip to content

Commit af77121

Browse files
committed
fix(ui): prevent double release of editor in EditorUtil
Add atomic boolean guard and disposal check to prevent TraceableDisposable$DisposalException when editor is released multiple times during disposal chain.
1 parent a3fa225 commit af77121

File tree

1 file changed

+13
-2
lines changed
  • core/src/main/kotlin/cc/unitmesh/devti/sketch/ui/code

1 file changed

+13
-2
lines changed

core/src/main/kotlin/cc/unitmesh/devti/sketch/ui/code/EditorUtil.kt

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import com.intellij.openapi.editor.highlighter.EditorHighlighterFactory
1919
import com.intellij.openapi.project.Project
2020
import com.intellij.openapi.vfs.VirtualFile
2121
import com.intellij.testFramework.LightVirtualFile
22+
import java.util.concurrent.atomic.AtomicBoolean
2223

2324
object EditorUtil {
2425
private val LINE_NO_REGEX = Regex("^\\d+:")
@@ -78,8 +79,18 @@ object EditorUtil {
7879
}
7980
}
8081

82+
val isReleased = AtomicBoolean(false)
8183
disposable.whenDisposed {
82-
EditorFactory.getInstance().releaseEditor(editor)
84+
if (isReleased.compareAndSet(false, true)) {
85+
try {
86+
if (!editor.isDisposed) {
87+
EditorFactory.getInstance().releaseEditor(editor)
88+
}
89+
} catch (e: Exception) {
90+
// Log the exception but don't let it propagate
91+
// to avoid breaking the disposal chain
92+
}
93+
}
8394
}
8495

8596
editor.setFile(file)
@@ -138,4 +149,4 @@ object EditorUtil {
138149

139150
return editor
140151
}
141-
}
152+
}

0 commit comments

Comments
 (0)