NationalSecurityAgency/ghidra · error · IllegalArgumentException
Cannot encode '<value>' for <dataTypeDisplayName>: <message>
Error message
Cannot encode '<value>' for <dataTypeDisplayName>: <message>
What it means
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.
Source
Thrown at Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/emulation/InputRow.java:74
void setValueStr(String string) {
RawStyle style = RawStyle.fromString(string);
byte[] value = style.fromString(string, length, language);
this.style = style;
this.value = value;
decodeValue();
}
void setRepr(String repr) {
String oldRepr = this.repr;
this.repr = repr;
try {
encodeRepr();
decodeValue();
}
catch (DataTypeEncodeException e) {
this.repr = oldRepr;
throw new IllegalArgumentException(e.getMessage(), e);
}
}
boolean isReprEditable() {
return repr != null && type.isEncodable();
}
}
View on GitHub (pinned to d5f144c24d)
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.
Example fix
// before
row.setRepr("abc"); // throws for an int type
// after
if (row.isReprEditable()) {
try {
row.setRepr("0x41");
} catch (IllegalArgumentException e) {
Msg.showError(this, null, "Bad Value", e.getMessage());
}
} Defensive patterns
Strategy: try-catch
Validate before calling
boolean editable = row.isReprEditable(); // repr != null && type.isEncodable()
Type guard
static boolean canEncode(InputRow r) {
return r.isReprEditable();
} Try / catch
try {
row.setRepr(input);
} catch (IllegalArgumentException e) {
// underlying DataTypeEncodeException is the cause
Msg.showError(this, null, "Invalid Value", e.getMessage());
} Prevention
- Prefer the raw-value field when unsure of representation grammar.
- Validate with isEncodable() before exposing the repr editor.
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- DataType %s has dynamic length
- Byte array values must be hex enclosed in {}
- Byte array values must be hex enclosed in {}
- Invalid address
- Executable
AI-assisted analysis of NationalSecurityAgency/ghidra@d5f144c24d (2026-08-14).
Data as JSON: /api/errors/06807a0b7e3ea4e8.
Report an issue: GitHub.