From 07fef358da067e72db774e75960e9d5ec5dc7118 Mon Sep 17 00:00:00 2001 From: "Egor.Ushakov" Date: Thu, 30 Oct 2014 21:14:35 +0300 Subject: [PATCH] IDEA-131931 Debugger: Throwable at SuspendContextImpl.getDebugProcess() on opening Referring Objects dialog from itself - better fix --- .../intellij/debugger/engine/JavaValue.java | 55 ++++++++++++------- .../debugger/engine/SuspendContextImpl.java | 4 ++ .../evaluation/EvaluationContextImpl.java | 4 ++ 3 files changed, 44 insertions(+), 19 deletions(-) diff --git a/java/debugger/impl/src/com/intellij/debugger/engine/JavaValue.java b/java/debugger/impl/src/com/intellij/debugger/engine/JavaValue.java index 6ea0b626cd00..a6b017dcfce1 100644 --- a/java/debugger/impl/src/com/intellij/debugger/engine/JavaValue.java +++ b/java/debugger/impl/src/com/intellij/debugger/engine/JavaValue.java @@ -120,12 +120,17 @@ public class JavaValue extends XNamedValue implements NodeDescriptorProvider, XV @Override public void computePresentation(@NotNull final XValueNode node, @NotNull XValuePlace place) { final SuspendContextImpl suspendContext = myEvaluationContext.getSuspendContext(); - scheduleCommand(new SuspendContextCommandImpl(suspendContext) { + myEvaluationContext.getManagerThread().schedule(new SuspendContextCommandImpl(suspendContext) { @Override public Priority getPriority() { return Priority.NORMAL; } + @Override + protected void commandCancelled() { + node.setPresentation(null, new JavaValuePresentation("", null, DebuggerBundle.message("error.context.has.changed")), false); + } + @Override public void contextAction() throws Exception { if (!myContextSet) { @@ -162,12 +167,17 @@ public class JavaValue extends XNamedValue implements NodeDescriptorProvider, XV node.setFullValueEvaluator(new XFullValueEvaluator() { @Override public void startEvaluation(@NotNull final XFullValueEvaluationCallback callback) { - scheduleCommand(new SuspendContextCommandImpl(suspendContext) { + myEvaluationContext.getManagerThread().schedule(new SuspendContextCommandImpl(suspendContext) { @Override public Priority getPriority() { return Priority.NORMAL; } + @Override + protected void commandCancelled() { + callback.errorOccurred(DebuggerBundle.message("error.context.has.changed")); + } + @Override public void contextAction() throws Exception { final String valueAsString = myValueDescriptor.getValueText(); @@ -352,31 +362,36 @@ public class JavaValue extends XNamedValue implements NodeDescriptorProvider, XV }); } - boolean scheduleCommand(SuspendContextCommandImpl command) { - return scheduleCommand(myEvaluationContext, null, command); - } - protected static boolean scheduleCommand(EvaluationContextImpl evaluationContext, - @Nullable XCompositeNode node, - SuspendContextCommandImpl command) { - if (evaluationContext.getSuspendContext().isResumed()) { - if (node != null) { + @NotNull final XCompositeNode node, + final SuspendContextCommandImpl command) { + evaluationContext.getManagerThread().schedule(new SuspendContextCommandImpl(command.getSuspendContext()) { + @Override + public void contextAction() throws Exception { + command.contextAction(); + } + + @Override + protected void commandCancelled() { node.setErrorMessage(DebuggerBundle.message("error.context.has.changed")); } - return false; - } - evaluationContext.getDebugProcess().getManagerThread().schedule(command); + }); return true; } @Override public void computeSourcePosition(@NotNull final XNavigatable navigatable) { - scheduleCommand(new SuspendContextCommandImpl(myEvaluationContext.getSuspendContext()) { + myEvaluationContext.getManagerThread().schedule(new SuspendContextCommandImpl(myEvaluationContext.getSuspendContext()) { @Override public Priority getPriority() { return Priority.NORMAL; } + @Override + protected void commandCancelled() { + navigatable.setSourcePosition(null); + } + @Override public void contextAction() throws Exception { ApplicationManager.getApplication().runReadAction(new Runnable() { @@ -452,9 +467,7 @@ public class JavaValue extends XNamedValue implements NodeDescriptorProvider, XV public String getEvaluationExpression() { if (evaluationExpression == null) { // TODO: change API to allow to calculate it asynchronously - if (myEvaluationContext.getSuspendContext().isResumed()) return null; - DebugProcessImpl debugProcess = myEvaluationContext.getDebugProcess(); - debugProcess.getManagerThread().invokeAndWait(new DebuggerCommandImpl() { + myEvaluationContext.getManagerThread().invokeAndWait(new DebuggerCommandImpl() { @Override public Priority getPriority() { return Priority.HIGH; @@ -501,11 +514,15 @@ public class JavaValue extends XNamedValue implements NodeDescriptorProvider, XV @Nullable @Override public XInstanceEvaluator getInstanceEvaluator() { - final DebugProcessImpl process = myEvaluationContext.getDebugProcess(); return new XInstanceEvaluator() { @Override public void evaluate(@NotNull final XDebuggerEvaluator.XEvaluationCallback callback, @NotNull final XStackFrame frame) { - process.getManagerThread().schedule(new DebuggerCommandImpl() { + myEvaluationContext.getManagerThread().schedule(new DebuggerCommandImpl() { + @Override + protected void commandCancelled() { + callback.errorOccurred(DebuggerBundle.message("error.context.has.changed")); + } + @Override protected void action() throws Exception { ValueDescriptorImpl inspectDescriptor = myValueDescriptor; 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 00aae83904ce..76c0484e83bc 100644 --- a/java/debugger/impl/src/com/intellij/debugger/engine/SuspendContextImpl.java +++ b/java/debugger/impl/src/com/intellij/debugger/engine/SuspendContextImpl.java @@ -126,6 +126,10 @@ public abstract class SuspendContextImpl extends XSuspendContext implements Susp return myDebugProcess; } + public DebugProcessImpl getDebugProcessNoAssert() { + return myDebugProcess; + } + @Override public StackFrameProxyImpl getFrameProxy() { assertNotResumed(); diff --git a/java/debugger/impl/src/com/intellij/debugger/engine/evaluation/EvaluationContextImpl.java b/java/debugger/impl/src/com/intellij/debugger/engine/evaluation/EvaluationContextImpl.java index 759d92fd57a8..252aca73cdc0 100644 --- a/java/debugger/impl/src/com/intellij/debugger/engine/evaluation/EvaluationContextImpl.java +++ b/java/debugger/impl/src/com/intellij/debugger/engine/evaluation/EvaluationContextImpl.java @@ -61,6 +61,10 @@ public final class EvaluationContextImpl implements EvaluationContext{ return getSuspendContext().getDebugProcess(); } + public DebuggerManagerThreadImpl getManagerThread() { + return getSuspendContext().getDebugProcessNoAssert().getManagerThread(); + } + @Override public Project getProject() { DebugProcessImpl debugProcess = getDebugProcess();