{"record":{"id":"e0624325e0b65764","repo":"NationalSecurityAgency/ghidra","slug":"overlay-space-name-duplicates-name-of-another","errorCode":null,"errorMessage":"Overlay space '${name}' duplicates name of another address space","messagePattern":"Overlay space '(.+?)' duplicates name of another address space","errorType":"validation","errorClass":"DuplicateNameException","httpStatus":null,"severity":"error","filePath":"Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/database/address/DBTraceOverlaySpaceAdapter.java","lineNumber":260,"sourceCode":"\t\tAddressSpace baseSpace = factory.getAddressSpace(ent.baseSpace);\n\t\tif (baseSpace == null) {\n\t\t\t// Error condition should be handled better - language may have dropped original base space\n\t\t\tthrow new RuntimeException(\"Base space for overlay not found: \" + ent.baseSpace);\n\t\t}\n\t\treturn baseSpace == os.getOverlayedSpace();\n\t}\n\n\tprotected AddressSpace doCreateOverlaySpace(String name, AddressSpace base)\n\t\t\tthrows DuplicateNameException {\n\t\tTraceAddressFactory factory = trace.getInternalAddressFactory();\n\n\t\tif (!factory.isValidOverlayBaseSpace(base)) {\n\t\t\tthrow new IllegalArgumentException(\n\t\t\t\t\"Invalid address space for overlay: \" + base.getName());\n\t\t}\n\n\t\tif (factory.getAddressSpace(name) != null) {\n\t\t\tthrow new DuplicateNameException(\n\t\t\t\t\"Overlay space '\" + name + \"' duplicates name of another address space\");\n\t\t}\n\n\t\tDBTraceOverlaySpaceEntry ent = overlayStore.create();\n\t\tProgramOverlayAddressSpace space = factory.addOverlaySpace(ent.getKey(), name, base);\n\n\t\t// Only if it succeeds do we store the record\n\t\tent.set(space.getName(), base.getName());\n\t\ttrace.updateViewsAddSpaceBlock(space);\n\t\ttrace.setChanged(\n\t\t\tnew TraceChangeRecord<>(TraceEvents.OVERLAY_ADDED, space, trace, null, space));\n\t\treturn space;\n\t}\n\n\tpublic AddressSpace createOverlayAddressSpace(String name, AddressSpace base)\n\t\t\tthrows DuplicateNameException {\n\t\t// TODO: Exclusive lock?\n\t\ttry (LockHold hold = LockHold.lock(lock.writeLock())) {","sourceCodeStart":242,"sourceCodeEnd":278,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/database/address/DBTraceOverlaySpaceAdapter.java#L242-L278","documentation":"In doCreateOverlaySpace, before creating, the code checks factory.getAddressSpace(name) != null and throws DuplicateNameException(\"Overlay space 'name' duplicates name of another address space\") on collision. The chosen overlay name must not match any existing address space in the trace's address factory (overlay or built-in).","triggerScenarios":"Creating an overlay whose name matches an existing overlay or built-in space; re-running creation code that does not deduplicate; importing content that already defined the space.","commonSituations":"Programmatic overlay creation with duplicate or generated names that clash; names like \"External\" or any built-in space name; re-running setup scripts against an already-populated trace.","solutions":["Use getOrCreateOverlayAddressSpace when idempotency is desired.","Check factory.getAddressSpace(name) == null before calling create.","Generate a unique name (append a suffix/counter) on collision."],"exampleFix":"// before\ntrace.createOverlayAddressSpace(\"ext\", base);\n\n// after\nString name = \"ext\";\nwhile (factory.getAddressSpace(name) != null) {\n    name = name + \"_\";\n}\ntrace.createOverlayAddressSpace(name, base);","handlingStrategy":"try-catch","validationCode":"if (factory.getAddressSpace(name) != null) {\n    // name taken; pick another or use getOrCreate\n}","typeGuard":null,"tryCatchPattern":"try { trace.createOverlayAddressSpace(name, base); }\ncatch (DuplicateNameException e) { /* choose unique name and retry */ }","preventionTips":["Prefer getOrCreateOverlayAddressSpace for idempotent setup.","Generate names with a counter/suffix scheme to avoid collisions.","Check the address factory for the name before any create call."],"tags":["overlay","duplicate-name","validation"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}