|
1 | 1 | /******************************************************************************* |
2 | | -* Copyright (c) 2017-2020 Microsoft Corporation and others. |
| 2 | +* Copyright (c) 2017-2021 Microsoft Corporation and others. |
3 | 3 | * All rights reserved. This program and the accompanying materials |
4 | 4 | * are made available under the terms of the Eclipse Public License v1.0 |
5 | 5 | * which accompanies this distribution, and is available at |
|
19 | 19 | import java.util.List; |
20 | 20 | import java.util.Map; |
21 | 21 | import java.util.Set; |
22 | | -import java.util.concurrent.CancellationException; |
23 | 22 | import java.util.concurrent.CompletableFuture; |
24 | | -import java.util.concurrent.ExecutionException; |
25 | 23 | import java.util.logging.Level; |
26 | 24 | import java.util.logging.Logger; |
27 | 25 | import java.util.stream.Collectors; |
@@ -133,7 +131,12 @@ public CompletableFuture<Response> handle(Command command, Arguments arguments, |
133 | 131 | try { |
134 | 132 | ObjectReference containerObj = (ObjectReference) containerNode.getProxiedVariable(); |
135 | 133 | if (DebugSettings.getCurrent().showLogicalStructure && evaluationEngine != null) { |
136 | | - JavaLogicalStructure logicalStructure = JavaLogicalStructureManager.getLogicalStructure(containerObj); |
| 134 | + JavaLogicalStructure logicalStructure = null; |
| 135 | + try { |
| 136 | + logicalStructure = JavaLogicalStructureManager.getLogicalStructure(containerObj); |
| 137 | + } catch (Exception e) { |
| 138 | + logger.log(Level.WARNING, "Failed to get the logical structure for the variable, fall back to the Object view.", e); |
| 139 | + } |
137 | 140 | if (isUnboundedTypeContainer && logicalStructure != null && containerEvaluateName != null) { |
138 | 141 | containerEvaluateName = "((" + logicalStructure.getFullyQualifiedName() + ")" + containerEvaluateName + ")"; |
139 | 142 | isUnboundedTypeContainer = false; |
@@ -162,11 +165,8 @@ public CompletableFuture<Response> handle(Command command, Arguments arguments, |
162 | 165 | childrenList.add(variable); |
163 | 166 | } |
164 | 167 | } |
165 | | - } catch (IllegalArgumentException | CancellationException | InterruptedException | ExecutionException e) { |
166 | | - logger.log(Level.WARNING, |
167 | | - String.format("Failed to get the logical structure for the type %s, fall back to the Object view.", |
168 | | - containerObj.type().name()), |
169 | | - e); |
| 168 | + } catch (Exception e) { |
| 169 | + logger.log(Level.WARNING, "Failed to get the logical structure for the variable, fall back to the Object view.", e); |
170 | 170 | } |
171 | 171 |
|
172 | 172 | logicalStructure = null; |
@@ -241,9 +241,8 @@ public CompletableFuture<Response> handle(Command command, Arguments arguments, |
241 | 241 | indexedVariables = ((IntegerValue) sizeValue).value(); |
242 | 242 | } |
243 | 243 | } |
244 | | - } catch (CancellationException | IllegalArgumentException | InterruptedException | ExecutionException | UnsupportedOperationException e) { |
245 | | - logger.log(Level.INFO, |
246 | | - String.format("Failed to get the logical size for the type %s.", value.type().name()), e); |
| 244 | + } catch (Exception e) { |
| 245 | + logger.log(Level.INFO, "Failed to get the logical size of the variable", e); |
247 | 246 | } |
248 | 247 | } |
249 | 248 |
|
@@ -275,15 +274,46 @@ public CompletableFuture<Response> handle(Command command, Arguments arguments, |
275 | 274 | varProxy.setUnboundedType(javaVariable.isUnboundedType()); |
276 | 275 | } |
277 | 276 |
|
278 | | - Types.Variable typedVariables = new Types.Variable(name, variableFormatter.valueToString(value, options), |
279 | | - variableFormatter.typeToString(value == null ? null : value.type(), options), |
280 | | - referenceId, evaluateName); |
| 277 | + boolean hasErrors = false; |
| 278 | + String valueString = null; |
| 279 | + try { |
| 280 | + valueString = variableFormatter.valueToString(value, options); |
| 281 | + } catch (OutOfMemoryError e) { |
| 282 | + hasErrors = true; |
| 283 | + logger.log(Level.SEVERE, "Failed to convert the value of a large object to a string", e); |
| 284 | + valueString = "<Unable to display the value of a large object>"; |
| 285 | + } catch (Exception e) { |
| 286 | + hasErrors = true; |
| 287 | + logger.log(Level.SEVERE, "Failed to resolve the variable value", e); |
| 288 | + valueString = "<Failed to resolve the variable value due to \"" + e.getMessage() + "\">"; |
| 289 | + } |
| 290 | + |
| 291 | + String typeString = ""; |
| 292 | + try { |
| 293 | + typeString = variableFormatter.typeToString(value == null ? null : value.type(), options); |
| 294 | + } catch (Exception e) { |
| 295 | + logger.log(Level.SEVERE, "Failed to resolve the variable type", e); |
| 296 | + typeString = ""; |
| 297 | + } |
| 298 | + |
| 299 | + Types.Variable typedVariables = new Types.Variable(name, valueString, typeString, referenceId, evaluateName); |
281 | 300 | typedVariables.indexedVariables = Math.max(indexedVariables, 0); |
| 301 | + |
282 | 302 | String detailsValue = null; |
283 | | - if (sizeValue != null) { |
| 303 | + if (hasErrors) { |
| 304 | + // If failed to resolve the variable value, skip the details info as well. |
| 305 | + } else if (sizeValue != null) { |
284 | 306 | detailsValue = "size=" + variableFormatter.valueToString(sizeValue, options); |
285 | 307 | } else if (DebugSettings.getCurrent().showToString) { |
286 | | - detailsValue = VariableDetailUtils.formatDetailsValue(value, containerNode.getThread(), variableFormatter, options, evaluationEngine); |
| 308 | + try { |
| 309 | + detailsValue = VariableDetailUtils.formatDetailsValue(value, containerNode.getThread(), variableFormatter, options, evaluationEngine); |
| 310 | + } catch (OutOfMemoryError e) { |
| 311 | + logger.log(Level.SEVERE, "Failed to compute the toString() value of a large object", e); |
| 312 | + detailsValue = "<Unable to display the details of a large object>"; |
| 313 | + } catch (Exception e) { |
| 314 | + logger.log(Level.SEVERE, "Failed to compute the toString() value", e); |
| 315 | + detailsValue = "<Failed to resolve the variable details due to \"" + e.getMessage() + "\">"; |
| 316 | + } |
287 | 317 | } |
288 | 318 |
|
289 | 319 | if (detailsValue != null) { |
|
0 commit comments