{"record":{"id":"1cf868b5b198615e","repo":"NationalSecurityAgency/ghidra","slug":"failed-to-resolve-data-type","errorCode":null,"errorMessage":"Failed to resolve data type","messagePattern":"Failed to resolve data type","errorType":"exception","errorClass":"CodeUnitInsertionException","httpStatus":null,"severity":"error","filePath":"Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/database/listing/DBTraceDefinedDataView.java","lineNumber":103,"sourceCode":"\t\t\t\t// TODO: Figure out the conflicting unit?\n\t\t\t\tthrow new CodeUnitInsertionException(\"Code units cannot overlap\");\n\t\t\t}\n\n\t\t\tDataType dataType;\n\t\t\tint length;\n\t\t\tif (origType instanceof FactoryDataType) {\n\t\t\t\tMemBuffer buffer = memSpace.getBufferAt(startSnap, address);\n\t\t\t\tFactoryDataType fdt = (FactoryDataType) origType;\n\t\t\t\tdataType = fdt.getDataType(buffer);\n\t\t\t\tlength = -1;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tdataType = origType;\n\t\t\t\tlength = origLength;\n\t\t\t}\n\n\t\t\tif (dataType == null) {\n\t\t\t\tthrow new CodeUnitInsertionException(\"Failed to resolve data type\");\n\t\t\t}\n\t\t\tDataTypeManager dtm = platform.getDataTypeManager();\n\t\t\tdataType = dataType.clone(dtm);\n\n\t\t\tif (isFunctionDefinition(dataType)) {\n\t\t\t\tdataType = new PointerDataType(dataType, dtm);\n\t\t\t\tlength = dataType.getLength();\n\t\t\t}\n\t\t\telse if (dataType instanceof Dynamic) {\n\t\t\t\t// TODO: Should I consider no observations to be \"uninitialized\"?\n\t\t\t\t// If so, dynamic types cannot be applied here\n\t\t\t\tDynamic dyn = (Dynamic) dataType;\n\t\t\t\tMemBuffer buffer = memSpace.getBufferAt(startSnap, address);\n\t\t\t\tlength = dyn.getLength(buffer, length);\n\t\t\t}\n\t\t\telse {\n\t\t\t\tlength = dataType.getLength();\n\t\t\t}","sourceCodeStart":85,"sourceCodeEnd":121,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/database/listing/DBTraceDefinedDataView.java#L85-L121","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Ensure memory bytes are written at the address before applying a factory type: trace.getMemoryManager().putBytes().","Use a concrete DataType instead of a factory type if the type is known.","Check the bytes at the address manually and choose the appropriate non-factory type."],"exampleFix":"// before\nview.create(lifespan, address, platform, factoryDataType); // factory returns null\n\n// after — write bytes first, or use a concrete type\ntrace.getMemoryManager().putBytes(snap, address, knownBytes);\nview.create(lifespan, address, platform, factoryDataType);\n// OR use a concrete type:\nview.create(lifespan, address, platform, DWordDataType.dataType);","handlingStrategy":"validation","validationCode":"// For factory types, pre-check if the factory can resolve the type\nif (origType instanceof FactoryDataType fdt) {\n    MemBuffer buffer = memSpace.getBufferAt(startSnap, address);\n    DataType resolved = fdt.getDataType(buffer);\n    if (resolved == null) {\n        // Cannot resolve — use a fallback type or skip\n        return;\n    }\n}\nview.create(lifespan, address, platform, origType);","typeGuard":null,"tryCatchPattern":"try {\n    view.create(lifespan, address, platform, origType);\n} catch (CodeUnitInsertionException e) {\n    if (e.getMessage().equals(\"Failed to resolve data type\")) {\n        // Factory type could not resolve — fall back to a concrete type\n        view.create(lifespan, address, platform, ByteDataType.dataType);\n    } else {\n        throw e;\n    }\n}","preventionTips":["Pre-test factory types by calling fdt.getDataType(buffer) and checking for null.","Ensure memory bytes are written before applying factory data types.","Provide fallback concrete data types when factory resolution is uncertain."],"tags":["data-type","factory-type","create","trace-modeling"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}