{"record":{"id":"06807a0b7e3ea4e8","repo":"NationalSecurityAgency/ghidra","slug":"cannot-encode-value-for-datatypedisplayname","errorCode":null,"errorMessage":"Cannot encode '<value>' for <dataTypeDisplayName>: <message>","messagePattern":"Cannot encode '<value>' for <dataTypeDisplayName>: <message>","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/emulation/InputRow.java","lineNumber":74,"sourceCode":"\n\tvoid setValueStr(String string) {\n\t\tRawStyle style = RawStyle.fromString(string);\n\t\tbyte[] value = style.fromString(string, length, language);\n\t\tthis.style = style;\n\t\tthis.value = value;\n\t\tdecodeValue();\n\t}\n\n\tvoid setRepr(String repr) {\n\t\tString oldRepr = this.repr;\n\t\tthis.repr = repr;\n\t\ttry {\n\t\t\tencodeRepr();\n\t\t\tdecodeValue();\n\t\t}\n\t\tcatch (DataTypeEncodeException e) {\n\t\t\tthis.repr = oldRepr;\n\t\t\tthrow new IllegalArgumentException(e.getMessage(), e);\n\t\t}\n\t}\n\n\tboolean isReprEditable() {\n\t\treturn repr != null && type.isEncodable();\n\t}\n}\n","sourceCodeStart":56,"sourceCodeEnd":82,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/emulation/InputRow.java#L56-L82","documentation":"Thrown by InputRow.setRepr when the user-entered representation string cannot be encoded into bytes by the row's DataType. The underlying DataTypeEncodeException (from DataType.encodeRepresentation) is caught and rethrown as IllegalArgumentException carrying its message. The value is reverted to the previous representation before throwing.","triggerScenarios":"User edits the 'Representation' cell of an input/output row in the Emulate Function dialog and enters a string the DataType rejects (e.g., 'abc' for an integer type, an out-of-range enum name, a malformed char literal).","commonSituations":"Typing a non-numeric string for a numeric type; entering an enum value that is not a member; malformed pointer/hex representations; encoding a value larger than the declared type length.","solutions":["Enter a value matching the data type's expected representation (e.g., decimal/hex integer for integral types, valid enum member for enums).","Use the raw-value (hex/bytes) field instead of the representation field when the representation grammar is unclear.","Check type.isEncodable() / isReprEditable() before attempting to edit the representation.","Inspect the DataType's documentation or schema for the accepted representation format."],"exampleFix":"// before\nrow.setRepr(\"abc\"); // throws for an int type\n\n// after\nif (row.isReprEditable()) {\n    try {\n        row.setRepr(\"0x41\");\n    } catch (IllegalArgumentException e) {\n        Msg.showError(this, null, \"Bad Value\", e.getMessage());\n    }\n}","handlingStrategy":"try-catch","validationCode":"boolean editable = row.isReprEditable(); // repr != null && type.isEncodable()","typeGuard":"static boolean canEncode(InputRow r) {\n    return r.isReprEditable();\n}","tryCatchPattern":"try {\n    row.setRepr(input);\n} catch (IllegalArgumentException e) {\n    // underlying DataTypeEncodeException is the cause\n    Msg.showError(this, null, \"Invalid Value\", e.getMessage());\n}","preventionTips":["Prefer the raw-value field when unsure of representation grammar.","Validate with isEncodable() before exposing the repr editor."],"tags":["datatype","encoding","user-input","representation"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}