NationalSecurityAgency/ghidra · error · CodeUnitInsertionException

Failed to resolve data type

Error message

Failed to resolve data type

What it means

Thrown by DBTraceDefinedDataView.create() when a FactoryDataType returns null from getDataType(buffer) — the factory could not determine a concrete data type from the bytes at the given address. Factory data types (like those used for auto-discovery) examine memory bytes to decide which type to instantiate; if the bytes do not match any known pattern, the factory returns null and no data unit can be created.

Source

Thrown at Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/database/listing/DBTraceDefinedDataView.java:103

				// TODO: Figure out the conflicting unit?
				throw new CodeUnitInsertionException("Code units cannot overlap");
			}

			DataType dataType;
			int length;
			if (origType instanceof FactoryDataType) {
				MemBuffer buffer = memSpace.getBufferAt(startSnap, address);
				FactoryDataType fdt = (FactoryDataType) origType;
				dataType = fdt.getDataType(buffer);
				length = -1;
			}
			else {
				dataType = origType;
				length = origLength;
			}

			if (dataType == null) {
				throw new CodeUnitInsertionException("Failed to resolve data type");
			}
			DataTypeManager dtm = platform.getDataTypeManager();
			dataType = dataType.clone(dtm);

			if (isFunctionDefinition(dataType)) {
				dataType = new PointerDataType(dataType, dtm);
				length = dataType.getLength();
			}
			else if (dataType instanceof Dynamic) {
				// TODO: Should I consider no observations to be "uninitialized"?
				// If so, dynamic types cannot be applied here
				Dynamic dyn = (Dynamic) dataType;
				MemBuffer buffer = memSpace.getBufferAt(startSnap, address);
				length = dyn.getLength(buffer, length);
			}
			else {
				length = dataType.getLength();
			}

View on GitHub (pinned to d5f144c24d)

Solutions

  1. Ensure memory bytes are written at the address before applying a factory type: trace.getMemoryManager().putBytes().
  2. Use a concrete DataType instead of a factory type if the type is known.
  3. Check the bytes at the address manually and choose the appropriate non-factory type.

Example fix

// before
view.create(lifespan, address, platform, factoryDataType); // factory returns null

// after — write bytes first, or use a concrete type
trace.getMemoryManager().putBytes(snap, address, knownBytes);
view.create(lifespan, address, platform, factoryDataType);
// OR use a concrete type:
view.create(lifespan, address, platform, DWordDataType.dataType);
Defensive patterns

Strategy: validation

Validate before calling

// For factory types, pre-check if the factory can resolve the type
if (origType instanceof FactoryDataType fdt) {
    MemBuffer buffer = memSpace.getBufferAt(startSnap, address);
    DataType resolved = fdt.getDataType(buffer);
    if (resolved == null) {
        // Cannot resolve — use a fallback type or skip
        return;
    }
}
view.create(lifespan, address, platform, origType);

Try / catch

try {
    view.create(lifespan, address, platform, origType);
} catch (CodeUnitInsertionException e) {
    if (e.getMessage().equals("Failed to resolve data type")) {
        // Factory type could not resolve — fall back to a concrete type
        view.create(lifespan, address, platform, ByteDataType.dataType);
    } else {
        throw e;
    }
}

Prevention

When it happens

Trigger: Calling create() with origType being a FactoryDataType (or subclass) where fdt.getDataType(buffer) evaluates to null because the bytes at (startSnap, address) do not match any factory-recognized pattern. This can also happen if the memory at the address is uninitialized (zeroed/unset).

Common situations: Applying a factory data type at an address where memory bytes are uninitialized or zero-filled; factory type's recognition logic does not match the actual data; using a factory type designed for a different architecture or byte pattern.

Related errors


AI-assisted analysis of NationalSecurityAgency/ghidra@d5f144c24d (2026-08-14). Data as JSON: /api/errors/1cf868b5b198615e. Report an issue: GitHub.