From 544a5807563b9844d6802dc10b94aa985f03d2d7 Mon Sep 17 00:00:00 2001 From: Eugene Zhuravlev Date: Thu, 7 Nov 2013 11:32:39 +0100 Subject: [PATCH] thread assertion fix --- .../ui/impl/watch/FieldDescriptorImpl.java | 51 ++++++++++++++----- 1 file changed, 39 insertions(+), 12 deletions(-) diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/impl/watch/FieldDescriptorImpl.java b/java/debugger/impl/src/com/intellij/debugger/ui/impl/watch/FieldDescriptorImpl.java index 521c2236639f..586dadfe5068 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/impl/watch/FieldDescriptorImpl.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/impl/watch/FieldDescriptorImpl.java @@ -18,12 +18,14 @@ package com.intellij.debugger.ui.impl.watch; import com.intellij.debugger.DebuggerBundle; import com.intellij.debugger.DebuggerContext; import com.intellij.debugger.SourcePosition; +import com.intellij.debugger.engine.DebugProcessImpl; import com.intellij.debugger.engine.DebuggerManagerThreadImpl; import com.intellij.debugger.engine.DebuggerUtils; import com.intellij.debugger.engine.JVMNameUtil; import com.intellij.debugger.engine.evaluation.EvaluateException; import com.intellij.debugger.engine.evaluation.EvaluateExceptionUtil; import com.intellij.debugger.engine.evaluation.EvaluationContextImpl; +import com.intellij.debugger.engine.events.DebuggerContextCommandImpl; import com.intellij.debugger.impl.DebuggerContextImpl; import com.intellij.debugger.impl.DebuggerSession; import com.intellij.debugger.impl.PositionUtil; @@ -32,6 +34,8 @@ import com.intellij.debugger.ui.tree.FieldDescriptor; import com.intellij.debugger.ui.tree.NodeDescriptor; import com.intellij.debugger.ui.tree.render.ClassRenderer; import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.Computable; +import com.intellij.openapi.util.Ref; import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.*; import com.intellij.psi.search.GlobalSearchScope; @@ -98,20 +102,43 @@ public class FieldDescriptorImpl extends ValueDescriptorImpl implements FieldDes PsiClass aClass = facade.findClass(type.name().replace('$', '.'), scope); if (aClass == null) { // trying to search, assuming declaring class is an anonymous class - try { - final List locations = type.allLineLocations(); - if (!locations.isEmpty()) { - // important: use the last location to be sure the position will be within the anonymous class - final Location lastLocation = locations.get(locations.size() - 1); - final SourcePosition position = context.getDebugProcess().getPositionManager().getSourcePosition(lastLocation); - if (position != null) { - aClass = JVMNameUtil.getClassAt(position); + final DebugProcessImpl debugProcess = context.getDebugProcess(); + if (debugProcess != null) { + final Computable classComputable = new Computable() { + public PsiClass compute() { + try { + final List locations = type.allLineLocations(); + if (!locations.isEmpty()) { + // important: use the last location to be sure the position will be within the anonymous class + final Location lastLocation = locations.get(locations.size() - 1); + final SourcePosition position = debugProcess.getPositionManager().getSourcePosition(lastLocation); + if (position != null) { + return JVMNameUtil.getClassAt(position); + } + } + } + catch (AbsentInformationException ignored) { + } + catch (ClassNotPreparedException ignored) { + } + return null; } + }; + if (!DebuggerManagerThreadImpl.isManagerThread()) { + final Ref classRef = new Ref(null); + debugProcess.getManagerThread().invokeAndWait(new DebuggerContextCommandImpl(context) { + public Priority getPriority() { + return Priority.HIGH; + } + public void threadAction() { + classRef.set(classComputable.compute()); + } + }); + aClass = classRef.get(); + } + else { + aClass = classComputable.compute(); } - } - catch (AbsentInformationException ignored) { - } - catch (ClassNotPreparedException ignored) { } }