NationalSecurityAgency/ghidra · error · IllegalArgumentException
Data not in a structure
Error message
Data not in a structure
What it means
Thrown by CreateStructureInStructureCmd.initializeStructureData when the parent datatype of the selected component is not a Structure. The command navigates comp1.getParent().getBaseDataType() and requires it to be a Structure to perform component replacement; a Union, Array, Typedef-to-non-structure, or other composite triggers the error.
Source
Thrown at Ghidra/Features/Base/src/main/java/ghidra/app/cmd/data/CreateStructureInStructureCmd.java:93
}
return structure;
}
/*
* @see AbstractCreateStructureCmd#initializeStructureData(StructureInfo)
*/
/*package*/ @Override
DataType initializeStructureData(Program program, Structure localStructure) {
Data data = program.getListing().getDataContaining(getStructureAddress());
Data comp1 = data.getComponent(fromPath);
Data comp2 = data.getComponent(toPath);
int dataLength = (comp2.getParentOffset() + comp2.getLength()) - comp1.getParentOffset();
DataType parentDataType = comp1.getParent().getBaseDataType();
if (!(parentDataType instanceof Structure)) {
throw new IllegalArgumentException("Data not in a structure");
}
Structure originalStructure = (Structure) parentDataType;
// clear and initialize the original structure and then get the new
// data
clearStruct(originalStructure, comp1.getParentOffset(), dataLength);
originalStructure.replace(comp1.getComponentIndex(), localStructure,
localStructure.getLength());
comp1 = data.getComponent(fromPath);
return comp1.getDataType();
}
private void clearStruct(Structure struct, int offset, int length) {
DataTypeComponent[] comps = struct.getDefinedComponents();
int endOffset = offset + length;
for (int i = comps.length - 1; i >= 0; i--) {
if (comps[i].getOffset() >= offset && comps[i].getOffset() < endOffset) {View on GitHub (pinned to d5f144c24d)
Solutions
- Run the command only when the parent composite is a Structure.
- Check `comp1.getParent().getBaseDataType() instanceof Structure` before invoking the command.
- For Unions, restructure the data differently - you cannot 'create structure in structure' inside a Union.
Example fix
// before
new CreateStructureInStructureCmd(addr, fromPath, toPath).applyTo(program);
// parent is a Union -> IllegalArgumentException
// after
Data comp1 = program.getListing().getDataContaining(addr).getComponent(fromPath);
if (!(comp1.getParent().getBaseDataType() instanceof Structure)) {
Msg.warn(this, "Cannot create structure-in-structure: parent is " +
comp1.getParent().getBaseDataType().getClass().getSimpleName());
return;
}
new CreateStructureInStructureCmd(addr, fromPath, toPath).applyTo(program); Defensive patterns
Strategy: type-guard
Validate before calling
Data comp1 = program.getListing().getDataContaining(addr).getComponent(fromPath);
DataType parent = comp1.getParent().getBaseDataType();
if (!(parent instanceof Structure)) {
// do not invoke CreateStructureInStructureCmd
} Type guard
boolean isInsideStructure(Program p, Address addr, int[] fromPath) {
Data comp = p.getListing().getDataContaining(addr).getComponent(fromPath);
return comp != null && comp.getParent() != null
&& comp.getParent().getBaseDataType() instanceof Structure;
} Try / catch
try {
cmd.applyTo(program);
} catch (IllegalArgumentException e) {
if ("Data not in a structure".equals(e.getMessage())) {
// user selected a Union/other composite; inform and abort
} else throw e;
} Prevention
- Confirm the parent composite is a Structure before running 'Create Structure' in a structure.
- Remember Unions are not valid parents for this command.
- Resolve Typedefs to their base type before the instanceof check.
When it happens
Trigger: Invoking CreateStructureInStructureCmd on a component whose parent is a Union (or other non-Structure composite). The fromPath/toPath must select components inside a Structure; using them against a Union's members violates the precondition.
Common situations: User selects a field inside a Union and runs 'Create Structure' in Ghidra. Programmatic use of CreateStructureInStructureCmd with a fromPath rooted in a non-Structure. Path computed against a Typedef that resolves to a Union.
Related errors
- Null datatype passed to getIsfObject
- Can't create structure because length exceeds address space
- Invalid number of elements specified: {}
- pos cannot be less than zero
- %s: unknown demangling style `%s'
AI-assisted analysis of NationalSecurityAgency/ghidra@d5f144c24d (2026-08-14).
Data as JSON: /api/errors/e097254a479eb8d6.
Report an issue: GitHub.