6565import com .sun .jdi .StringReference ;
6666import com .sun .jdi .Type ;
6767import com .sun .jdi .Value ;
68+ import com .sun .jdi .PrimitiveType ;
69+ import com .sun .jdi .ClassNotLoadedException ;
6870
6971public 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