{"record":{"id":"c974c63216ab7ef3","repo":"NationalSecurityAgency/ghidra","slug":"given-reference-is-not-in-this-trace","errorCode":null,"errorMessage":"Given reference is not in this trace","messagePattern":"Given reference is not in this trace","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/database/symbol/DBTraceReferenceManager.java","lineNumber":112,"sourceCode":"\t\t}\n\t\tDBTraceReferenceSpace space = getReferenceSpace(entry.toAddrMin.getAddressSpace(), false);\n\t\tassert space != null;\n\t\tspace.doDelXRef(entry);\n\t}\n\n\tprotected void doSetXRefLifespan(DBTraceReferenceEntry entry) {\n\t\tif (!entry.toAddrMin.isMemoryAddress()) {\n\t\t\treturn;\n\t\t}\n\t\tDBTraceReferenceSpace space = getReferenceSpace(entry.toAddrMin.getAddressSpace(), false);\n\t\tassert space != null;\n\t\tspace.doSetXRefLifespan(entry);\n\t}\n\n\t// Internal\n\tpublic DBTraceReference assertIsMine(Reference ref) {\n\t\tif (!(ref instanceof DBTraceReference)) {\n\t\t\tthrow new IllegalArgumentException(\"Given reference is not in this trace\");\n\t\t}\n\t\tDBTraceReference dbRef = (DBTraceReference) ref;\n\t\tif (dbRef.ent.space.manager != this) {\n\t\t\tthrow new IllegalArgumentException(\"Given reference is not in this trace\");\n\t\t}\n\t\treturn dbRef;\n\t}\n\n\t@Override\n\tpublic DBTraceReferenceSpace getReferenceSpace(AddressSpace space, boolean createIfAbsent) {\n\t\treturn getForSpace(space, createIfAbsent);\n\t}\n\n\t@Override\n\tpublic DBTraceReferenceSpace getReferenceRegisterSpace(TraceThread thread,\n\t\t\tboolean createIfAbsent) {\n\t\treturn getForRegisterSpace(thread, 0, createIfAbsent);\n\t}","sourceCodeStart":94,"sourceCodeEnd":130,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/database/symbol/DBTraceReferenceManager.java#L94-L130","documentation":"Thrown as IllegalArgumentException by DBTraceReferenceManager.assertIsMine when the given Reference is not a DBTraceReference, or is a DBTraceReference whose backing entry's manager is not this manager. This guarantees a reference belongs to the same trace before mutating or querying it through this manager. Foreign references (from another trace or a flat Program) are rejected.","triggerScenarios":"Passing a Program-style Reference into a trace reference manager; passing a DBTraceReference from traceA into traceB's manager; passing a custom Reference implementation.","commonSituations":"Code shared between Program and Trace APIs that forwards a Reference blindly; multi-trace sessions reusing a reference object; cross-trace copy logic.","solutions":["Obtain references only from the same trace's reference manager: trace.getReferenceManager().getReferences(...).","Before asserting ownership, check ref instanceof DBTraceReference and compare its trace to yours.","When copying between traces, recreate the reference on the target rather than reusing the object."],"exampleFix":"// before\notherMgr.assertIsMine(refFromOtherTrace);\n// after\nReference mine =\n    trace.getReferenceManager().addReference(snap, from, to, refType);","handlingStrategy":"validation","validationCode":"if (ref instanceof DBTraceReference) {\n    DBTraceReference d = (DBTraceReference) ref;\n    if (d.ent.space.manager == myMgr) {\n        myMgr.assertIsMine(ref);\n    }\n}","typeGuard":"static boolean refBelongsToMgr(Reference r, DBTraceReferenceManager m) {\n    return r instanceof DBTraceReference d && d.ent.space.manager == m;\n}","tryCatchPattern":null,"preventionTips":["Obtain references only from the same trace's reference manager.","Recreate references when copying across traces."],"tags":["reference","ownership","validation","trace"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}