From 52bdda13805967ca02c32b1e546eebbff9b11fd1 Mon Sep 17 00:00:00 2001 From: Maksim Zuev Date: Tue, 1 Oct 2024 18:21:25 +0200 Subject: [PATCH] [debugger] EA-1376775 Fix dispose SuspendContextImpl GitOrigin-RevId: 35d4183b8a8fd37035a90dd829b1565c618d561f --- .../intellij/debugger/engine/SuspendContextImpl.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/java/debugger/impl/src/com/intellij/debugger/engine/SuspendContextImpl.java b/java/debugger/impl/src/com/intellij/debugger/engine/SuspendContextImpl.java index 25d066c8095d..dc82573790ba 100644 --- a/java/debugger/impl/src/com/intellij/debugger/engine/SuspendContextImpl.java +++ b/java/debugger/impl/src/com/intellij/debugger/engine/SuspendContextImpl.java @@ -16,6 +16,7 @@ import com.intellij.debugger.jdi.VirtualMachineProxyImpl; import com.intellij.debugger.settings.DebuggerSettings; import com.intellij.openapi.Disposable; import com.intellij.openapi.diagnostic.Logger; +import com.intellij.openapi.util.CheckedDisposable; import com.intellij.openapi.util.Disposer; import com.intellij.xdebugger.frame.XExecutionStack; import com.intellij.xdebugger.frame.XSuspendContext; @@ -95,7 +96,14 @@ public abstract class SuspendContextImpl extends XSuspendContext implements Susp myVotesToVote = eventVotes; myEventSet = set; myDebugId = debugId; - Disposer.register(debugProcess.disposable, this); + CheckedDisposable disposable = debugProcess.disposable; + if (disposable.isDisposed()) { + // could be due to VM death + Disposer.dispose(this); + } + else { + Disposer.register(disposable, this); + } } public VirtualMachineProxyImpl getVirtualMachineProxy() { @@ -131,7 +139,7 @@ public abstract class SuspendContextImpl extends XSuspendContext implements Susp } private void setThread(@Nullable ThreadReferenceProxyImpl threadProxy) { - if (threadProxy != null && myThread != threadProxy) { // do not add more than once + if (threadProxy != null && myThread != threadProxy && !myDebugProcess.disposable.isDisposed()) { // do not add more than once threadProxy.addListener(myListener, this); } myThread = threadProxy;