Skip to content

Commit 38a87db

Browse files
committed
Merge tag '0.34.0' into main
2 parents 9d88e12 + 719eb8c commit 38a87db

File tree

17 files changed

+595
-79
lines changed

17 files changed

+595
-79
lines changed

ThirdPartyNotices.txt

Lines changed: 437 additions & 0 deletions
Large diffs are not rendered by default.

com.microsoft.java.debug.core/pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<name>${base.name} :: Debugger Core</name>
88
<description>The Java Debug Server is an implementation of Visual Studio Code (VSCode) Debug Protocol. It can be used in Visual Studio Code to debug Java programs.</description>
99
<url>https://github.com/Microsoft/java-debug</url>
10-
<version>0.32.0+1-SNAPSHOT</version>
10+
<version>0.34.0+1-SNAPSHOT</version>
1111
<packaging>jar</packaging>
1212
<properties>
1313
<base.name>Java Debug Server for Visual Studio Code</base.name>
@@ -126,7 +126,7 @@
126126
<dependency>
127127
<groupId>com.google.code.gson</groupId>
128128
<artifactId>gson</artifactId>
129-
<version>2.7</version>
129+
<version>2.8.9</version>
130130
</dependency>
131131
<dependency>
132132
<groupId>io.reactivex.rxjava2</groupId>
@@ -141,7 +141,7 @@
141141
<dependency>
142142
<groupId>commons-io</groupId>
143143
<artifactId>commons-io</artifactId>
144-
<version>2.5</version>
144+
<version>2.10.0</version>
145145
</dependency>
146146
<!-- Dependencies for test -->
147147
<dependency>

com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/ProcessConsole.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public void stop() {
129129
}
130130

131131
private void monitor(InputStream input, PublishSubject<String> subject) {
132-
BufferedReader reader = new BufferedReader(new InputStreamReader(input, encoding));
132+
BufferedReader reader = new BufferedReader(encoding == null ? new InputStreamReader(input) : new InputStreamReader(input, encoding));
133133
final int BUFFERSIZE = 4096;
134134
char[] buffer = new char[BUFFERSIZE];
135135
while (true) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111

1212
package com.microsoft.java.debug.core.adapter.handler;
1313

14-
import java.util.ArrayList;
1514
import java.util.Arrays;
15+
import java.util.Collections;
1616
import java.util.List;
1717
import java.util.concurrent.CompletableFuture;
1818

@@ -46,7 +46,7 @@ public CompletableFuture<Response> handle(Command command, Arguments arguments,
4646
// completions should be illegal when frameId is zero, it is sent when the program is running, while during running we cannot resolve
4747
// the completion candidates
4848
if (completionsArgs.frameId == 0) {
49-
response.body = new ArrayList<>();
49+
response.body = new Responses.CompletionsResponseBody(Collections.emptyList());
5050
return CompletableFuture.completedFuture(response);
5151
}
5252

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

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2017-2020 Microsoft Corporation and others.
2+
* Copyright (c) 2017-2021 Microsoft Corporation and others.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v1.0
55
* which accompanies this distribution, and is available at
@@ -14,7 +14,6 @@
1414
import java.util.Arrays;
1515
import java.util.List;
1616
import java.util.Map;
17-
import java.util.concurrent.CancellationException;
1817
import java.util.concurrent.CompletableFuture;
1918
import java.util.concurrent.CompletionException;
2019
import java.util.concurrent.ExecutionException;
@@ -106,31 +105,58 @@ public CompletableFuture<Response> handle(Command command, Arguments arguments,
106105
indexedVariables = ((IntegerValue) sizeValue).value();
107106
}
108107
}
109-
} catch (CancellationException | IllegalArgumentException | InterruptedException
110-
| ExecutionException | UnsupportedOperationException e) {
111-
logger.log(Level.INFO,
112-
String.format("Failed to get the logical size for the type %s.", value.type().name()), e);
108+
} catch (Exception e) {
109+
logger.log(Level.INFO, "Failed to get the logical size of the variable", e);
113110
}
114111
}
115112
int referenceId = 0;
116113
if (indexedVariables > 0 || (indexedVariables < 0 && value instanceof ObjectReference)) {
117114
referenceId = context.getRecyclableIdPool().addObject(threadId, varProxy);
118115
}
119116

120-
String valueString = variableFormatter.valueToString(value, options);
117+
boolean hasErrors = false;
118+
String valueString = null;
119+
try {
120+
valueString = variableFormatter.valueToString(value, options);
121+
} catch (OutOfMemoryError e) {
122+
hasErrors = true;
123+
logger.log(Level.SEVERE, "Failed to convert the value of a large object to a string", e);
124+
valueString = "<Unable to display the value of a large object>";
125+
} catch (Exception e) {
126+
hasErrors = true;
127+
logger.log(Level.SEVERE, "Failed to resolve the variable value", e);
128+
valueString = "<Failed to resolve the variable value due to \"" + e.getMessage() + "\">";
129+
}
130+
121131
String detailsString = null;
122-
if (sizeValue != null) {
132+
if (hasErrors) {
133+
// If failed to resolve the variable value, skip the details info as well.
134+
} else if (sizeValue != null) {
123135
detailsString = "size=" + variableFormatter.valueToString(sizeValue, options);
124136
} else if (DebugSettings.getCurrent().showToString) {
125-
detailsString = VariableDetailUtils.formatDetailsValue(value, stackFrameReference.getThread(), variableFormatter, options, engine);
137+
try {
138+
detailsString = VariableDetailUtils.formatDetailsValue(value, stackFrameReference.getThread(), variableFormatter, options, engine);
139+
} catch (OutOfMemoryError e) {
140+
logger.log(Level.SEVERE, "Failed to compute the toString() value of a large object", e);
141+
detailsString = "<Unable to display the details of a large object>";
142+
} catch (Exception e) {
143+
logger.log(Level.SEVERE, "Failed to compute the toString() value", e);
144+
detailsString = "<Failed to resolve the variable details due to \"" + e.getMessage() + "\">";
145+
}
126146
}
127147

128148
if ("clipboard".equals(evalArguments.context) && detailsString != null) {
129149
response.body = new Responses.EvaluateResponseBody(detailsString, -1, "String", 0);
130150
} else {
151+
String typeString = "";
152+
try {
153+
typeString = variableFormatter.typeToString(value == null ? null : value.type(), options);
154+
} catch (Exception e) {
155+
logger.log(Level.SEVERE, "Failed to resolve the variable type", e);
156+
typeString = "";
157+
}
131158
response.body = new Responses.EvaluateResponseBody((detailsString == null) ? valueString : valueString + " " + detailsString,
132-
referenceId, variableFormatter.typeToString(value == null ? null : value.type(), options),
133-
Math.max(indexedVariables, 0));
159+
referenceId, typeString, Math.max(indexedVariables, 0));
134160
}
135161
return response;
136162
}

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

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import java.net.MalformedURLException;
1717
import java.net.URISyntaxException;
1818
import java.nio.charset.Charset;
19-
import java.nio.charset.StandardCharsets;
2019
import java.nio.file.Path;
2120
import java.nio.file.Paths;
2221
import java.util.ArrayList;
@@ -91,23 +90,21 @@ protected CompletableFuture<Response> handleLaunchCommand(Arguments arguments, R
9190
"Failed to launch debuggee VM. Missing mainClass or modulePaths/classPaths options in launch configuration.",
9291
ErrorCode.ARGUMENT_MISSING);
9392
}
94-
if (StringUtils.isBlank(launchArguments.encoding)) {
95-
context.setDebuggeeEncoding(StandardCharsets.UTF_8);
96-
} else {
93+
if (StringUtils.isNotBlank(launchArguments.encoding)) {
9794
if (!Charset.isSupported(launchArguments.encoding)) {
9895
throw AdapterUtils.createCompletionException(
9996
"Failed to launch debuggee VM. 'encoding' options in the launch configuration is not recognized.",
10097
ErrorCode.INVALID_ENCODING);
10198
}
10299
context.setDebuggeeEncoding(Charset.forName(launchArguments.encoding));
100+
if (StringUtils.isBlank(launchArguments.vmArgs)) {
101+
launchArguments.vmArgs = String.format("-Dfile.encoding=%s", context.getDebuggeeEncoding().name());
102+
} else {
103+
// if vmArgs already has the file.encoding settings, duplicate options for jvm will not cause an error, the right most value wins
104+
launchArguments.vmArgs = String.format("%s -Dfile.encoding=%s", launchArguments.vmArgs, context.getDebuggeeEncoding().name());
105+
}
103106
}
104107

105-
if (StringUtils.isBlank(launchArguments.vmArgs)) {
106-
launchArguments.vmArgs = String.format("-Dfile.encoding=%s", context.getDebuggeeEncoding().name());
107-
} else {
108-
// if vmArgs already has the file.encoding settings, duplicate options for jvm will not cause an error, the right most value wins
109-
launchArguments.vmArgs = String.format("%s -Dfile.encoding=%s", launchArguments.vmArgs, context.getDebuggeeEncoding().name());
110-
}
111108
context.setLaunchMode(launchArguments.noDebug ? LaunchMode.NO_DEBUG : LaunchMode.DEBUG);
112109

113110
activeLaunchHandler.preLaunch(launchArguments, context);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,11 @@ public static synchronized Path generateClasspathJar(String[] classPaths) throws
7373
public static synchronized Path generateArgfile(String[] classPaths, String[] modulePaths) throws IOException {
7474
String argfile = "";
7575
if (ArrayUtils.isNotEmpty(classPaths)) {
76-
argfile = "-classpath \"" + String.join(File.pathSeparator, classPaths) + "\"";
76+
argfile = "-cp \"" + String.join(File.pathSeparator, classPaths) + "\"";
7777
}
7878

7979
if (ArrayUtils.isNotEmpty(modulePaths)) {
80-
argfile = " --module-path \"" + String.join(File.pathSeparator, modulePaths) + "\"";
80+
argfile += " --module-path \"" + String.join(File.pathSeparator, modulePaths) + "\"";
8181
}
8282

8383
argfile = argfile.replace("\\", "\\\\");

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,20 +145,22 @@ public CompletableFuture<Response> handle(Command command, Arguments arguments,
145145
private void handleDebugEvent(DebugEvent debugEvent, IDebugSession debugSession, IDebugAdapterContext context,
146146
ThreadState threadState) {
147147
Event event = debugEvent.event;
148+
EventRequestManager eventRequestManager = debugSession.getVM().eventRequestManager();
148149

149150
// When a breakpoint occurs, abort any pending step requests from the same thread.
150151
if (event instanceof BreakpointEvent || event instanceof ExceptionEvent) {
151152
long threadId = ((LocatableEvent) event).thread().uniqueID();
152153
if (threadId == threadState.threadId && threadState.pendingStepRequest != null) {
153-
threadState.deleteStepRequests(debugSession.getVM().eventRequestManager());
154+
threadState.deleteStepRequest(eventRequestManager);
155+
threadState.deleteMethodExitRequest(eventRequestManager);
154156
context.getStepResultManager().removeMethodResult(threadId);
155157
if (threadState.eventSubscription != null) {
156158
threadState.eventSubscription.dispose();
157159
}
158160
}
159161
} else if (event instanceof StepEvent) {
160162
ThreadReference thread = ((StepEvent) event).thread();
161-
threadState.deleteStepRequests(debugSession.getVM().eventRequestManager());
163+
threadState.deleteStepRequest(eventRequestManager);
162164
if (isStepFiltersConfigured(context.getStepFilters())) {
163165
try {
164166
if (threadState.pendingStepType == Command.STEPIN) {
@@ -181,6 +183,7 @@ private void handleDebugEvent(DebugEvent debugEvent, IDebugSession debugSession,
181183
// ignore.
182184
}
183185
}
186+
threadState.deleteMethodExitRequest(eventRequestManager);
184187
if (threadState.eventSubscription != null) {
185188
threadState.eventSubscription.dispose();
186189
}
@@ -280,10 +283,13 @@ class ThreadState {
280283
Location stepLocation = null;
281284
Disposable eventSubscription = null;
282285

283-
public void deleteStepRequests(EventRequestManager manager) {
284-
DebugUtility.deleteEventRequestSafely(manager, this.pendingStepRequest);
286+
public void deleteMethodExitRequest(EventRequestManager manager) {
285287
DebugUtility.deleteEventRequestSafely(manager, this.pendingMethodExitRequest);
286288
this.pendingMethodExitRequest = null;
289+
}
290+
291+
public void deleteStepRequest(EventRequestManager manager) {
292+
DebugUtility.deleteEventRequestSafely(manager, this.pendingStepRequest);
287293
this.pendingStepRequest = null;
288294
}
289295
}

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

Lines changed: 47 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2017-2020 Microsoft Corporation and others.
2+
* Copyright (c) 2017-2021 Microsoft Corporation and others.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v1.0
55
* which accompanies this distribution, and is available at
@@ -19,9 +19,7 @@
1919
import java.util.List;
2020
import java.util.Map;
2121
import java.util.Set;
22-
import java.util.concurrent.CancellationException;
2322
import java.util.concurrent.CompletableFuture;
24-
import java.util.concurrent.ExecutionException;
2523
import java.util.logging.Level;
2624
import java.util.logging.Logger;
2725
import java.util.stream.Collectors;
@@ -136,7 +134,12 @@ public CompletableFuture<Response> handle(Command command, Arguments arguments,
136134
try {
137135
ObjectReference containerObj = (ObjectReference) containerNode.getProxiedVariable();
138136
if (DebugSettings.getCurrent().showLogicalStructure && evaluationEngine != null) {
139-
JavaLogicalStructure logicalStructure = JavaLogicalStructureManager.getLogicalStructure(containerObj);
137+
JavaLogicalStructure logicalStructure = null;
138+
try {
139+
logicalStructure = JavaLogicalStructureManager.getLogicalStructure(containerObj);
140+
} catch (Exception e) {
141+
logger.log(Level.WARNING, "Failed to get the logical structure for the variable, fall back to the Object view.", e);
142+
}
140143
if (isUnboundedTypeContainer && logicalStructure != null && containerEvaluateName != null) {
141144
containerEvaluateName = "((" + logicalStructure.getFullyQualifiedName() + ")" + containerEvaluateName + ")";
142145
isUnboundedTypeContainer = false;
@@ -165,11 +168,8 @@ public CompletableFuture<Response> handle(Command command, Arguments arguments,
165168
childrenList.add(variable);
166169
}
167170
}
168-
} catch (IllegalArgumentException | CancellationException | InterruptedException | ExecutionException e) {
169-
logger.log(Level.WARNING,
170-
String.format("Failed to get the logical structure for the type %s, fall back to the Object view.",
171-
containerObj.type().name()),
172-
e);
171+
} catch (Exception e) {
172+
logger.log(Level.WARNING, "Failed to get the logical structure for the variable, fall back to the Object view.", e);
173173
}
174174

175175
logicalStructure = null;
@@ -244,9 +244,8 @@ public CompletableFuture<Response> handle(Command command, Arguments arguments,
244244
indexedVariables = ((IntegerValue) sizeValue).value();
245245
}
246246
}
247-
} catch (CancellationException | IllegalArgumentException | InterruptedException | ExecutionException | UnsupportedOperationException e) {
248-
logger.log(Level.INFO,
249-
String.format("Failed to get the logical size for the type %s.", value.type().name()), e);
247+
} catch (Exception e) {
248+
logger.log(Level.INFO, "Failed to get the logical size of the variable", e);
250249
}
251250
}
252251

@@ -278,15 +277,46 @@ public CompletableFuture<Response> handle(Command command, Arguments arguments,
278277
varProxy.setUnboundedType(javaVariable.isUnboundedType());
279278
}
280279

281-
Types.Variable typedVariables = new Types.Variable(name, variableFormatter.valueToString(value, options),
282-
variableFormatter.typeToString(value == null ? null : value.type(), options),
283-
referenceId, evaluateName);
280+
boolean hasErrors = false;
281+
String valueString = null;
282+
try {
283+
valueString = variableFormatter.valueToString(value, options);
284+
} catch (OutOfMemoryError e) {
285+
hasErrors = true;
286+
logger.log(Level.SEVERE, "Failed to convert the value of a large object to a string", e);
287+
valueString = "<Unable to display the value of a large object>";
288+
} catch (Exception e) {
289+
hasErrors = true;
290+
logger.log(Level.SEVERE, "Failed to resolve the variable value", e);
291+
valueString = "<Failed to resolve the variable value due to \"" + e.getMessage() + "\">";
292+
}
293+
294+
String typeString = "";
295+
try {
296+
typeString = variableFormatter.typeToString(value == null ? null : value.type(), options);
297+
} catch (Exception e) {
298+
logger.log(Level.SEVERE, "Failed to resolve the variable type", e);
299+
typeString = "";
300+
}
301+
302+
Types.Variable typedVariables = new Types.Variable(name, valueString, typeString, referenceId, evaluateName);
284303
typedVariables.indexedVariables = Math.max(indexedVariables, 0);
304+
285305
String detailsValue = null;
286-
if (sizeValue != null) {
306+
if (hasErrors) {
307+
// If failed to resolve the variable value, skip the details info as well.
308+
} else if (sizeValue != null) {
287309
detailsValue = "size=" + variableFormatter.valueToString(sizeValue, options);
288310
} else if (DebugSettings.getCurrent().showToString) {
289-
detailsValue = VariableDetailUtils.formatDetailsValue(value, containerNode.getThread(), variableFormatter, options, evaluationEngine);
311+
try {
312+
detailsValue = VariableDetailUtils.formatDetailsValue(value, containerNode.getThread(), variableFormatter, options, evaluationEngine);
313+
} catch (OutOfMemoryError e) {
314+
logger.log(Level.SEVERE, "Failed to compute the toString() value of a large object", e);
315+
detailsValue = "<Unable to display the details of a large object>";
316+
} catch (Exception e) {
317+
logger.log(Level.SEVERE, "Failed to compute the toString() value", e);
318+
detailsValue = "<Failed to resolve the variable details due to \"" + e.getMessage() + "\">";
319+
}
290320
}
291321

292322
if (detailsValue != null) {

0 commit comments

Comments
 (0)