Skip to content

Commit f420492

Browse files
Fix the InvalidStackFrameException when getting variables at the exception breakpoint (#340)
Signed-off-by: Jinbo Wang <[email protected]>
1 parent 54b1fed commit f420492

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/handler/ExceptionInfoRequestHandler.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,15 @@ public CompletableFuture<Response> handle(Command command, Arguments arguments,
8080
} catch (InvalidTypeException | ClassNotLoadedException | IncompatibleThreadStateException
8181
| InvocationException e) {
8282
logger.log(Level.SEVERE, String.format("Failed to get the return value of the method Exception.toString(): %s", e.toString(), e));
83+
} finally {
84+
try {
85+
// See bug https://github.com/microsoft/vscode-java-debug/issues/767:
86+
// The operation exception.invokeMethod above will resume the thread, that will cause
87+
// the previously cached stack frames for this thread to be invalid.
88+
context.getStackFrameManager().reloadStackFrames(thread);
89+
} catch (Exception e) {
90+
// do nothing.
91+
}
8392
}
8493
}
8594

com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/variables/VariableUtils.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,10 @@ public static List<Variable> listLocalVariables(StackFrame stackFrame) throws Ab
149149
return res;
150150
}
151151
try {
152-
for (LocalVariable localVariable : stackFrame.visibleVariables()) {
153-
Variable var = new Variable(localVariable.name(), stackFrame.getValue(localVariable));
152+
List<LocalVariable> localVariables = stackFrame.visibleVariables();
153+
Map<LocalVariable, Value> values = stackFrame.getValues(localVariables);
154+
for (LocalVariable localVariable : localVariables) {
155+
Variable var = new Variable(localVariable.name(), values.get(localVariable));
154156
var.local = localVariable;
155157
res.add(var);
156158
}

0 commit comments

Comments
 (0)