{"record":{"id":"00cb3f83151da3bf","repo":"NationalSecurityAgency/ghidra","slug":"cannot-convert-register-value-class-val","errorCode":null,"errorMessage":"Cannot convert register value: ({class}) '{val}'","messagePattern":"Cannot convert register value: \\((.+?)\\) '(.+?)'","errorType":"exception","errorClass":"RegisterValueException","httpStatus":null,"severity":"error","filePath":"Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/model/memory/RegisterValueConverter.java","lineNumber":64,"sourceCode":"\t\t\t// NOTE: Reg object values are always big endian\n\t\t\treturn new BigInteger(1, arr);\n\t\t}\n\t\telse if (val instanceof Byte b) {\n\t\t\treturn BigInteger.valueOf(b);\n\t\t}\n\t\telse if (val instanceof Short s) {\n\t\t\treturn BigInteger.valueOf(s);\n\t\t}\n\t\telse if (val instanceof Integer i) {\n\t\t\treturn BigInteger.valueOf(i);\n\t\t}\n\t\telse if (val instanceof Long l) {\n\t\t\treturn BigInteger.valueOf(l);\n\t\t}\n\t\telse if (val instanceof Address a) {\n\t\t\treturn a.getOffsetAsBigInteger();\n\t\t}\n\t\tthrow new RegisterValueException(\n\t\t\t\"Cannot convert register value: (\" + val.getClass() + \") '\" + val + \"'\");\n\t}\n\n\tBigInteger convertRegisterValueToBigInteger() throws RegisterValueException {\n\t\treturn convertValueToBigInteger(registerValue.getValue());\n\t}\n\n\tint getRegisterValueBitLength() throws RegisterValueException {\n\t\tObject objBitLength = registerValue.getParent()\n\t\t\t\t.getValue(registerValue.getMinSnap(), TraceRegister.KEY_BITLENGTH)\n\t\t\t\t.getValue();\n\t\tif (!(objBitLength instanceof Number numBitLength)) {\n\t\t\tthrow new RegisterValueException(\n\t\t\t\t\"Register length is not numeric: (\" + objBitLength.getClass() + \") '\" +\n\t\t\t\t\tobjBitLength + \"'\");\n\t\t}\n\t\treturn numBitLength.intValue();\n\t}","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/model/memory/RegisterValueConverter.java#L46-L82","documentation":"Thrown by RegisterValueConverter.convertValueToBigInteger for a value whose Java type is none of the supported cases (String, byte[], Byte, Short, Integer, Long, Address). The converter cannot turn an arbitrary object into a BigInteger register value, so it reports the unexpected class and value.","triggerScenarios":"A TraceObjectValue's register value is of an unsupported type such as Long[], BigInteger, Boolean, a composite object, or a list/map, and getValue() is called on its converter.","commonSituations":"A target connector serializes registers into an array or BigInteger instead of a primitive/byte[]; schema changes that store values differently; prototype/test data with wrong types.","solutions":["Store the register value as one of the supported types (prefer byte[] or a hex String).","Convert the value to a supported type before attaching it to the register object.","Catch RegisterValueException and log the class/value to locate the mis-typed source."],"exampleFix":"// before\nobj.setAttribute(span, regKey, bigIntValue /* BigInteger - unsupported */);\n\n// after\nobj.setAttribute(span, regKey, bigIntValue.toByteArray()); // byte[] supported","handlingStrategy":"try-catch","validationCode":"if (!(val instanceof String || val instanceof byte[]\n        || val instanceof Number || val instanceof Address)) {\n    val = toSupported(val); // e.g. BigInteger -> byte[], or Long[] -> byte[]\n}","typeGuard":"static boolean supportedValueType(Object val) {\n    return val instanceof String || val instanceof byte[]\n        || val instanceof Byte || val instanceof Short\n        || val instanceof Integer || val instanceof Long\n        || val instanceof Address;\n}","tryCatchPattern":"try {\n    BigInteger v = new RegisterValueConverter(regVal).getValue();\n} catch (RegisterValueException e) {\n    // log val.getClass() from e.getMessage(); coerce source type and retry\n}","preventionTips":["Write register values as byte[] or a hex String (the most portable forms).","Convert BigInteger/array/composite values to byte[] before storing.","Unit-test value types your connector emits."],"tags":["ghidra","trace-modeling","register-value","type-mismatch"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}