{"record":{"id":"e985fc6a538ee149","repo":"oracle/graal","slug":"boxed-object-is-not-a-primitive","errorCode":null,"errorMessage":"boxed object: {} is not a primitive","messagePattern":"boxed object: (.+?) is not a primitive","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"espresso/src/com.oracle.truffle.espresso.jdwp/src/com/oracle/truffle/espresso/jdwp/api/TagConstants.java","lineNumber":84,"sourceCode":"        if (boxed instanceof Double) {\n            return DOUBLE;\n        }\n        if (boxed instanceof Long) {\n            return LONG;\n        }\n        if (boxed instanceof Byte) {\n            return BYTE;\n        }\n        if (boxed instanceof Short) {\n            return SHORT;\n        }\n        if (boxed instanceof Character) {\n            return CHAR;\n        }\n        if (boxed instanceof Boolean) {\n            return BOOLEAN;\n        }\n        throw new RuntimeException(\"boxed object: \" + boxed.getClass() + \" is not a primitive\");\n    }\n\n    public static byte toTagConstant(JavaKind kind) {\n        switch (kind) {\n            case Boolean:\n                return TagConstants.BOOLEAN;\n            case Byte:\n                return TagConstants.BYTE;\n            case Short:\n                return TagConstants.SHORT;\n            case Char:\n                return TagConstants.CHAR;\n            case Int:\n                return TagConstants.INT;\n            case Float:\n                return TagConstants.FLOAT;\n            case Long:\n                return TagConstants.LONG;","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/oracle/graal/blob/a66e9ccd1d7bf2552883939aa0788dfd0e294aab/espresso/src/com.oracle.truffle.espresso.jdwp/src/com/oracle/truffle/espresso/jdwp/api/TagConstants.java#L66-L102","documentation":"Thrown by TagConstants.getTagFromPrimitive(Object boxed) when the argument is none of the eight primitive wrappers (Integer, Float, Double, Long, Byte, Short, Character, Boolean). The JDWP protocol assigns a one-byte tag to every value it serializes, and this helper maps a boxed primitive to its tag; a non-primitive object has no primitive tag, so the mapping is a caller bug, not an environmental condition.","triggerScenarios":"A JDWP back-end code path (e.g. building a Value packet for a watched field or method return) calls getTagFromPrimitive on a value that is actually a String, an array, null, or a plain object; null fails earlier at boxed.getClass() with an NPE if not guarded.","commonSituations":"Debugger-plugin code in Espresso that assumes a static field type guarantees a primitive value (obfuscated/recycled classes where the declared type lies), or new JDWP command implementations routing reference values through the primitive mapper.","solutions":["Branch on the value first: use getTagFromPrimitive only when value instanceof Number, Character, or Boolean","Handle reference values with the OBJECT/STRING/ARRAY/THREAD tags before calling the primitive mapper","Null-check the boxed value before mapping"],"exampleFix":"// before\nbyte tag = TagConstants.getTagFromPrimitive(value);\n\n// after\nbyte tag;\nif (value == null || !(value instanceof Number || value instanceof Character || value instanceof Boolean)) {\n    tag = TagConstants.OBJECT;\n} else {\n    tag = TagConstants.getTagFromPrimitive(value);\n}","handlingStrategy":"type-guard","validationCode":"if (!(boxed instanceof Number || boxed instanceof Character || boxed instanceof Boolean)) {\n    // route to reference-value tag handling instead\n}","typeGuard":"static boolean isBoxedPrimitive(Object v) {\n    return v instanceof Number || v instanceof Character || v instanceof Boolean;\n}","tryCatchPattern":"catch (RuntimeException e) when message contains 'not a primitive': map value to TagConstants.OBJECT and continue serialization.","preventionTips":["Always branch primitive vs reference before tag mapping","Null-check values before calling getTagFromPrimitive"],"tags":["espresso","jdwp","debugging","type-mapping"],"backgroundTag":null,"analyzedSha":"a66e9ccd1d7bf2552883939aa0788dfd0e294aab","analyzedAt":"2026-08-14T13:58:47.161Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}