{"record":{"id":"7cee5588a2255086","repo":"NationalSecurityAgency/ghidra","slug":"thread-with-key-d-does-not-exist-in-given-trace","errorCode":null,"errorMessage":"Thread with key %d does not exist in given trace","messagePattern":"Thread with key (.+?) does not exist in given trace","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/model/time/schedule/Step.java","lineNumber":115,"sourceCode":"\tdefault int getTypeOrder() {\n\t\treturn getType().ordinal();\n\t}\n\n\tboolean isNop();\n\n\tlong getThreadKey();\n\n\tdefault boolean isEventThread() {\n\t\treturn getThreadKey() == -1;\n\t}\n\n\tstatic TraceThread requireThread(TraceThread thread, long key) {\n\t\tif (thread == null) {\n\t\t\tif (key == -1) {\n\t\t\t\tthrow new IllegalArgumentException(\"Thread must be given, e.g., 0:t1-3, \" +\n\t\t\t\t\t\"since the last thread or snapshot event thread is not given.\");\n\t\t\t}\n\t\t\tthrow new IllegalArgumentException(\n\t\t\t\t\"Thread with key %d does not exist in given trace\".formatted(key));\n\t\t}\n\t\treturn thread;\n\t}\n\n\tdefault TraceThread getThread(TraceThreadManager tm, TraceThread eventThread) {\n\t\tlong key = getThreadKey();\n\t\treturn requireThread(isEventThread() ? eventThread : tm.getThread(key), key);\n\t}\n\n\tlong getTickCount();\n\n\tlong getSkipCount();\n\n\tlong getPatchCount();\n\n\t/**\n\t * Check if the given step can be combined with this one","sourceCodeStart":97,"sourceCodeEnd":133,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/model/time/schedule/Step.java#L97-L133","documentation":"Step.requireThread throws this when the resolved thread is null but a specific key (not -1) was requested. This means threadManager.getThread(key) returned null — no thread with that key exists in the trace. The key is a long identifier assigned to each thread when it is created in the trace.","triggerScenarios":"Calling step.getThread() where the step references a thread key that does not exist in the trace's ThreadManager. Using a schedule from a different trace session where thread keys were assigned differently. Referencing a thread that was deleted or never created.","commonSituations":"Reusing a schedule string across trace sessions — thread keys are per-trace and may differ. Deleting a thread from the trace after the schedule was created. Loading a trace that was partially corrupted or is missing thread records. Using stale schedule bookmarks from a previous emulation session.","solutions":["List available threads and their keys: trace.getThreadManager().getAllThreads() and use a valid key","Re-derive the schedule from the current trace's thread keys","If the thread was deleted, either recreate it or update the schedule to reference an existing thread","Validate the key before stepping: trace.getThreadManager().getThread(key) != null"],"exampleFix":"// before\n// t5 may not exist in this trace\nTraceSchedule.parse(\"0:t5-10\", Source.ABNORMAL, TimeRadix.DEC);\n// after\n// look up an actual thread key\nTraceThread t = trace.getThreadManager().getAllThreads().get(0);\nString spec = \"0:t\" + t.getKey() + \"-10\";\nTraceSchedule.parse(spec, Source.ABNORMAL, TimeRadix.DEC);","handlingStrategy":"validation","validationCode":"boolean threadExists(Trace trace, long key) {\n    return key == -1 || trace.getThreadManager().getThread(key) != null;\n}","typeGuard":"// N/A","tryCatchPattern":"try {\n    TraceThread thread = step.getThread(tm, eventThread);\n} catch (IllegalArgumentException e) {\n    // thread key is stale; list available threads\n    List<TraceThread> all = tm.getAllThreads();\n    // re-derive schedule with a valid key\n}","preventionTips":["Never assume thread keys persist across trace sessions","Validate keys against the current trace's ThreadManager before stepping","When loading saved schedules, re-map thread keys to the current trace"],"tags":["ghidra","trace-schedule","thread","precondition"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}