{"record":{"id":"ac4de8f1806c5afc","repo":"JetBrains/intellij-community","slug":"cannot-convert-to-primitive-value-of-type","errorCode":null,"errorMessage":"Cannot convert to primitive value of type ","messagePattern":"Cannot convert to primitive value of type ","errorType":"exception","errorClass":"EvaluateException","httpStatus":null,"severity":"error","filePath":"java/debugger/impl/src/com/intellij/debugger/engine/evaluation/expression/UnBoxingEvaluator.java","lineNumber":88,"sourceCode":"      final Couple<String> pair = TYPES_TO_CONVERSION_METHOD_MAP.get(valueTypeName);\n      if (pair != null) {\n        return convertToPrimitive(context, (ObjectReference)value, pair.getFirst(), pair.getSecond());\n      }\n    }\n    return value;\n  }\n\n  private static Value convertToPrimitive(EvaluationContext context, ObjectReference value, final String conversionMethodName,\n                                          String conversionMethodSignature) throws EvaluateException {\n    // for speedup first try value field\n    Value primitiveValue = getInnerPrimitiveValue(value, true).join();\n    if (primitiveValue != null) {\n      return primitiveValue;\n    }\n\n    Method method = DebuggerUtils.findMethod(value.referenceType(), conversionMethodName, conversionMethodSignature);\n    if (method == null) {\n      throw new EvaluateException(\"Cannot convert to primitive value of type \" + value.type() + \": Unable to find method \" +\n                                  conversionMethodName + conversionMethodSignature);\n    }\n\n    return context.getDebugProcess().invokeMethod(context, value, method, Collections.emptyList());\n  }\n\n  public static CompletableFuture<PrimitiveValue> getInnerPrimitiveValue(@Nullable ObjectReference value, boolean now) {\n    if (value != null) {\n      ReferenceType type = value.referenceType();\n      return fields(type, now)\n        .thenCompose(fields -> {\n          Field valueField = ContainerUtil.find(fields, f -> \"value\".equals(f.name()));\n          if (valueField != null) {\n            return getValue(value, valueField, now)\n              .thenApply(primitiveValue -> {\n                if (primitiveValue instanceof PrimitiveValue) {\n                  String expected = PsiJavaParserFacadeImpl.getPrimitiveType(primitiveValue.type().name()).getBoxedTypeName();\n                  String actual = type.name();","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/JetBrains/intellij-community/blob/be881553f2a76ac8b4ea53950d93f0de78295c19/java/debugger/impl/src/com/intellij/debugger/engine/evaluation/expression/UnBoxingEvaluator.java#L70-L106","documentation":"Thrown by UnBoxingEvaluator.convertToPrimitive when the value to unbox has no accessible 'value' field and no conversion method (intValue, longValue, ...) with the expected signature on its reference type. Only objects whose type provides the standard wrapper conversion method can be converted to a primitive during evaluation.","triggerScenarios":"unbox() looks up TYPES_TO_CONVERSION_METHOD_MAP by the object's type name; for a registered wrapper name the fast path reads the 'value' field, otherwise convertToPrimitive calls DebuggerUtils.findMethod(value.referenceType(), conversionMethodName, signature); if both the field and the method are missing (method == null), EvaluateException('Cannot convert to primitive value of type ' + value.type() + ...) is thrown.","commonSituations":"Debuggee running a non-standard class library where java.lang.Integer etc. lack intValue/value; unboxing an object whose class merely shares a wrapper name but lives in a different package/classloader; exotic JVMs (older Android runtime, JME) with trimmed java.lang.","solutions":["Run the debuggee on a standard JDK/Android runtime with full java.lang wrapper classes","Avoid unboxing in the evaluated expression; keep the wrapper and call a method on it instead","Extract the value explicitly, e.g. String.valueOf(boxed) instead of (primitive) boxed"],"exampleFix":"// before: int v = boxed;  // boxed's runtime lacks intValue\n\n// after: String s = String.valueOf(boxed);","handlingStrategy":"validation","validationCode":"Couple<String> pair = TYPES_TO_CONVERSION_METHOD_MAP.get(value.type().name());\nMethod m = pair != null ? DebuggerUtils.findMethod(value.referenceType(), pair.getFirst(), pair.getSecond()) : null;\nif (m == null && getInnerPrimitiveValue(value, true).join() == null) {\n  // avoid unboxing: keep wrapper or use String.valueOf\n}","typeGuard":"static boolean isStandardWrapper(ObjectReference ref) {\n  return TYPES_TO_CONVERSION_METHOD_MAP.containsKey(ref.type().name());\n}","tryCatchPattern":"try {\n  Value prim = UnBoxingEvaluator.convertToPrimitive(context, value, name, sig);\n} catch (EvaluateException e) {\n  // fall back to reading the 'value' field directly or String.valueOf\n}","preventionTips":["Debug on a runtime with standard java.lang wrapper classes","Avoid primitive casts on wrapper-like objects in fragments","Extract values via toString/String.valueOf when unboxing support is unclear"],"tags":["debugger","evaluation","unboxing","jdi"],"backgroundTag":null,"analyzedSha":"be881553f2a76ac8b4ea53950d93f0de78295c19","analyzedAt":"2026-08-14T14:13:06.425Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}