{"record":{"id":"110097889981b9b4","repo":"NationalSecurityAgency/ghidra","slug":"cannot-delete-an-undefined-code-unit","errorCode":null,"errorMessage":"Cannot delete an undefined code unit","messagePattern":"Cannot delete an undefined code unit","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/database/listing/UndefinedDBTraceData.java","lineNumber":77,"sourceCode":"\t */\n\tpublic UndefinedDBTraceData(DBTrace trace, long snap, Address address, TraceThread thread,\n\t\t\tint frameLevel) {\n\t\tthis.trace = trace;\n\t\tthis.snap = snap;\n\t\tthis.lifespan = Lifespan.at(snap);\n\t\tthis.address = address;\n\t\tthis.thread = thread;\n\t\tthis.frameLevel = frameLevel;\n\t}\n\n\t@Override\n\tpublic AddressSpace getAddressSpace() {\n\t\treturn address.getAddressSpace();\n\t}\n\n\t@Override\n\tpublic void delete() {\n\t\tthrow new UnsupportedOperationException(\"Cannot delete an undefined code unit\");\n\t}\n\n\t@Override\n\tpublic DBTrace getTrace() {\n\t\treturn trace;\n\t}\n\n\t@Override\n\tpublic Language getLanguage() {\n\t\treturn trace.getBaseLanguage();\n\t}\n\n\t@Override\n\tpublic TracePlatform getPlatform() {\n\t\treturn trace.getPlatformManager().getHostPlatform();\n\t}\n\n\t@Override","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/database/listing/UndefinedDBTraceData.java#L59-L95","documentation":"Thrown by UndefinedDBTraceData.delete() — always, unconditionally. UndefinedDBTraceData represents an ephemeral, non-persisted code unit that fills gaps in the trace listing where no defined instruction or data exists. Since it is not backed by any database table, there is nothing to delete. Calling delete() is a programming error.","triggerScenarios":"Calling delete() on any UndefinedDBTraceData instance, which is returned by the trace listing API for addresses where no defined code unit exists at a given snap. For example, iterating code units and calling delete() on one that happens to be an undefined placeholder.","commonSituations":"Generic code that iterates over code units and unconditionally calls delete() without checking the concrete type. Migration or cleanup scripts that try to remove all units at an address, including ephemeral ones.","solutions":["Check the code unit type before calling delete(): use instanceof to verify it is not UndefinedDBTraceData, or check getCodeUnitType() / isDefined().","Only call delete() on DBTraceInstruction or defined DBTraceData instances.","Filter out undefined units before processing a collection."],"exampleFix":"// before\nfor (CodeUnit cu : codeUnits) {\n    cu.delete();\n}\n\n// after\nfor (CodeUnit cu : codeUnits) {\n    if (!(cu instanceof UndefinedDBTraceData)) {\n        cu.delete();\n    }\n}","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"// Type guard: check before calling delete()\nstatic boolean isDeletable(CodeUnit cu) {\n    return !(cu instanceof UndefinedDBTraceData);\n}\n\n// Usage:\nif (isDeletable(cu)) {\n    cu.delete();\n}","tryCatchPattern":null,"preventionTips":["Always check the concrete type before calling delete() on code units.","Use instanceof UndefinedDBTraceData to filter out ephemeral units.","Remember that undefined units are generated on-the-fly and have no database backing."],"tags":["trace-database","undefined-data","unsupported-operation","unchecked-exception","code-unit"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}