Skip to content

Commit 45ef1b8

Browse files
Fixed issue with lazy VariablePresentationHint.
Restricted constant to Primitive & StringRefs
1 parent b368760 commit 45ef1b8

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@
6565
import com.sun.jdi.StringReference;
6666
import com.sun.jdi.Type;
6767
import com.sun.jdi.Value;
68+
import com.sun.jdi.PrimitiveType;
69+
import com.sun.jdi.ClassNotLoadedException;
6870

6971
public class VariablesRequestHandler implements IDebugRequestHandler {
7072
protected static final Logger logger = Logger.getLogger(Configuration.LOGGER_NAME);
@@ -375,7 +377,7 @@ public CompletableFuture<Response> handle(Command command, Arguments arguments,
375377
Types.Variable typedVariables = new Types.Variable(name, valueString, typeString, referenceId, evaluateName);
376378
typedVariables.indexedVariables = Math.max(indexedVariables, 0);
377379
if ((varProxy != null && varProxy.isLazyVariable()) || (rawAttributes.length > 0)) {
378-
typedVariables.presentationHint = new VariablePresentationHint(varProxy == null || varProxy.isLazyVariable(), rawAttributes);
380+
typedVariables.presentationHint = new VariablePresentationHint(varProxy != null && varProxy.isLazyVariable(), rawAttributes);
379381
}
380382

381383
if (detailsValue != null) {
@@ -400,14 +402,22 @@ private String[] extractAttributes(Variable variable) {
400402
attributes.add("static");
401403
}
402404
if (variable.field.isFinal()) {
403-
// static final fields are compile-time constants in Java
404-
if (variable.field.isStatic()) {
405+
// static final Primitive or StringRef fields are compile-time constants in Java
406+
boolean isPrimitive;
407+
try {
408+
isPrimitive = variable.field.type() instanceof PrimitiveType;
409+
} catch (ClassNotLoadedException e) { /* type() not yet loaded indicates some ReferenceType */
410+
isPrimitive = false;
411+
}
412+
boolean canBeTrueConstant = (isPrimitive || variable.field instanceof StringReference);
413+
if (variable.field.isStatic() && canBeTrueConstant) {
405414
attributes.add("constant");
406415
}
407416
attributes.add("readOnly");
408417
}
409418
}
410419
// local 'final' variables get inlined by the compiler and do not appear
420+
411421
if (variable.value instanceof StringReference) {
412422
attributes.add("rawString");
413423
}

0 commit comments

Comments
 (0)