JetBrains/intellij-community · error · EvaluateException
Cannot convert to primitive value of type
Error message
Cannot convert to primitive value of type
What it means
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.
Source
Thrown at java/debugger/impl/src/com/intellij/debugger/engine/evaluation/expression/UnBoxingEvaluator.java:88
final Couple<String> pair = TYPES_TO_CONVERSION_METHOD_MAP.get(valueTypeName);
if (pair != null) {
return convertToPrimitive(context, (ObjectReference)value, pair.getFirst(), pair.getSecond());
}
}
return value;
}
private static Value convertToPrimitive(EvaluationContext context, ObjectReference value, final String conversionMethodName,
String conversionMethodSignature) throws EvaluateException {
// for speedup first try value field
Value primitiveValue = getInnerPrimitiveValue(value, true).join();
if (primitiveValue != null) {
return primitiveValue;
}
Method method = DebuggerUtils.findMethod(value.referenceType(), conversionMethodName, conversionMethodSignature);
if (method == null) {
throw new EvaluateException("Cannot convert to primitive value of type " + value.type() + ": Unable to find method " +
conversionMethodName + conversionMethodSignature);
}
return context.getDebugProcess().invokeMethod(context, value, method, Collections.emptyList());
}
public static CompletableFuture<PrimitiveValue> getInnerPrimitiveValue(@Nullable ObjectReference value, boolean now) {
if (value != null) {
ReferenceType type = value.referenceType();
return fields(type, now)
.thenCompose(fields -> {
Field valueField = ContainerUtil.find(fields, f -> "value".equals(f.name()));
if (valueField != null) {
return getValue(value, valueField, now)
.thenApply(primitiveValue -> {
if (primitiveValue instanceof PrimitiveValue) {
String expected = PsiJavaParserFacadeImpl.getPrimitiveType(primitiveValue.type().name()).getBoxedTypeName();
String actual = type.name();View on GitHub (pinned to be881553f2)
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
Example fix
// before: int v = boxed; // boxed's runtime lacks intValue // after: String s = String.valueOf(boxed);
Defensive patterns
Strategy: validation
Validate before calling
Couple<String> pair = TYPES_TO_CONVERSION_METHOD_MAP.get(value.type().name());
Method m = pair != null ? DebuggerUtils.findMethod(value.referenceType(), pair.getFirst(), pair.getSecond()) : null;
if (m == null && getInnerPrimitiveValue(value, true).join() == null) {
// avoid unboxing: keep wrapper or use String.valueOf
} Type guard
static boolean isStandardWrapper(ObjectReference ref) {
return TYPES_TO_CONVERSION_METHOD_MAP.containsKey(ref.type().name());
} Try / catch
try {
Value prim = UnBoxingEvaluator.convertToPrimitive(context, value, name, sig);
} catch (EvaluateException e) {
// fall back to reading the 'value' field directly or String.valueOf
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Interface method invocation is not supported in JVM {}. Use
- Cannot construct wrapper object for value of type {}: Unable
- java.lang.NullPointerException: cannot unbox null value
- Variable ''{0}'' is already declared
- Local variable declarations are not supported here.
AI-assisted analysis of JetBrains/intellij-community@be881553f2 (2026-08-14).
Data as JSON: /api/errors/ac4de8f1806c5afc.
Report an issue: GitHub.