{"record":{"id":"bb3a6d547aa6a8d2","repo":"JetBrains/intellij-community","slug":"cannot-construct-wrapper-object-for-value-of-type","errorCode":null,"errorMessage":"Cannot construct wrapper object for value of type {}: Unable to find either valueOf() or constructor method","messagePattern":"Cannot construct wrapper object for value of type (.+?): Unable to find either valueOf\\(\\) or constructor method","errorType":"exception","errorClass":"EvaluateException","httpStatus":null,"severity":"error","filePath":"java/debugger/impl/src/com/intellij/debugger/engine/evaluation/expression/BoxingEvaluator.java","lineNumber":55,"sourceCode":"      if (primitiveType != null) {\n        return convertToWrapper(context, primitiveValue, primitiveType.getBoxedTypeName());\n      }\n    }\n    return value;\n  }\n\n  private static Value convertToWrapper(EvaluationContextImpl context, PrimitiveValue value, String wrapperTypeName) throws\n                                                                                                                     EvaluateException {\n    final DebugProcessImpl process = context.getDebugProcess();\n    final ClassType wrapperClass = (ClassType)process.findClass(context, wrapperTypeName, null);\n    final String methodSignature = \"(\" + JVMNameUtil.getPrimitiveSignature(value.type().name()) + \")L\" + wrapperTypeName.replace('.', '/') + \";\";\n\n    Method method = DebuggerUtils.findMethod(wrapperClass, \"valueOf\", methodSignature);\n    if (method == null) { // older JDK version\n      method = DebuggerUtils.findMethod(wrapperClass, JVMNameUtil.CONSTRUCTOR_NAME, methodSignature);\n    }\n    if (method == null) {\n      throw new EvaluateException(\"Cannot construct wrapper object for value of type \" + value.type() + \": Unable to find either valueOf() or constructor method\");\n    }\n\n    Method finalMethod = method;\n    List<PrimitiveValue> args = Collections.singletonList(value);\n    return context.computeAndKeep(() -> process.invokeMethod(context, wrapperClass, finalMethod, args, true));\n  }\n}\n","sourceCodeStart":37,"sourceCodeEnd":63,"githubUrl":"https://github.com/JetBrains/intellij-community/blob/be881553f2a76ac8b4ea53950d93f0de78295c19/java/debugger/impl/src/com/intellij/debugger/engine/evaluation/expression/BoxingEvaluator.java#L37-L63","documentation":"Thrown by BoxingEvaluator.convertToWrapper when it tries to box a primitive value into its wrapper type (e.g. int to Integer) but can find neither a static valueOf(primitive) method nor a constructor with matching signature on the wrapper class in the debuggee VM. This happens on very old or non-standard JVM class libraries where the wrapper API differs.","triggerScenarios":"An evaluation assigns a primitive to a variable/parameter of wrapper type (autoboxing), forcing BoxingEvaluator to look up 'valueOf' or '<init>' with signature '(X)Ljava/lang/Integer;' on the loaded wrapper class; DebuggerUtils.findMethod returns null for both lookups on old JDK versions.","commonSituations":"Evaluating expressions that rely on autoboxing while debugging on JDK 1.4/1.5-era runtimes or exotic JVMs; debugging a debuggee whose java.lang wrapper classes are stubs (Android early versions, some embedded JVMs).","solutions":["Run the debuggee on a standard modern JDK where java.lang wrappers define valueOf","Rewrite the evaluated expression to call Integer.valueOf(x) explicitly or use the primitive type directly","Avoid mixing primitive and wrapper types in the evaluated expression"],"exampleFix":"// before (evaluation input): Integer x = 5;\n\n// after (evaluation input): int x = 5;","handlingStrategy":"validation","validationCode":"Method m = DebuggerUtils.findMethod(wrapperClass, \"valueOf\", sig);\nif (m == null) m = DebuggerUtils.findMethod(wrapperClass, \"<init>\", sig);\nif (m == null) {\n  // skip boxing: use the primitive value directly or a modern JVM\n}","typeGuard":null,"tryCatchPattern":"try {\n  return process.invokeMethod(context, wrapperClass, finalMethod, args, true);\n} catch (EvaluateException e) {\n  // fall back to primitive arithmetic without boxing\n}","preventionTips":["Debug on a standard JDK whose java.lang wrappers define valueOf","Keep evaluated expressions in primitive types to avoid implicit boxing"],"tags":["debugger","evaluation","boxing","jdi"],"backgroundTag":null,"analyzedSha":"be881553f2a76ac8b4ea53950d93f0de78295c19","analyzedAt":"2026-08-14T14:13:06.425Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}