Skip to content

Commit 93963b9

Browse files
authored
Show target VM exceptions as result in evaluate requests (#428)
This changes the result of an expression like `Long.parseLong("foo")` sent to the evaluate handler from: org.eclipse.debug.core.DebugException: com.sun.jdi.InvocationException: Exception occurred in target VM occurred invoking method. to the actual exception: NumberFormatException@76 "java.lang.NumberFormatException: For input string: "foo"" backtrace: Object[6]@82 cause: NumberFormatException@76 depth: 46 detailMessage: "For input string: "foo"" stackTrace: StackTraceElement[0]@84 suppressedExceptions: Collections$EmptyList@85 size=0
1 parent 1fcbe70 commit 93963b9

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

com.microsoft.java.debug.plugin/src/main/java/com/microsoft/java/debug/plugin/internal/eval/JdtEvaluationProvider.java

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.apache.commons.lang3.reflect.FieldUtils;
3030
import org.eclipse.core.resources.IWorkspaceRoot;
3131
import org.eclipse.core.resources.ResourcesPlugin;
32+
import org.eclipse.core.runtime.IStatus;
3233
import org.eclipse.debug.core.DebugException;
3334
import org.eclipse.debug.core.ILaunch;
3435
import org.eclipse.debug.core.ILaunchConfiguration;
@@ -328,9 +329,22 @@ private void internalEvaluate(ASTEvaluationEngine engine, ICompiledExpression co
328329
try {
329330
engine.evaluateExpression(compiledExpression, stackframe, evaluateResult -> {
330331
if (evaluateResult == null || evaluateResult.hasErrors()) {
331-
Exception ex = evaluateResult.getException() != null ? evaluateResult.getException()
332-
: new RuntimeException(StringUtils.join(evaluateResult.getErrorMessages()));
333-
completableFuture.completeExceptionally(ex);
332+
DebugException debugException = evaluateResult.getException();
333+
if (debugException == null) {
334+
completableFuture.completeExceptionally(
335+
new RuntimeException(String.join(" ", evaluateResult.getErrorMessages())));
336+
return;
337+
}
338+
IStatus status = debugException.getStatus();
339+
if (status.getCode() == DebugException.TARGET_REQUEST_FAILED) {
340+
Throwable innerException = status.getException();
341+
if (innerException instanceof com.sun.jdi.InvocationException) {
342+
ObjectReference objectReference = ((com.sun.jdi.InvocationException) innerException).exception();
343+
completableFuture.complete(objectReference);
344+
return;
345+
}
346+
}
347+
completableFuture.completeExceptionally(debugException);
334348
return;
335349
}
336350
try {

0 commit comments

Comments
 (0)