{"record":{"id":"28d2b2ae7069c27b","repo":"NationalSecurityAgency/ghidra","slug":"given-range-s-space-must-be-in-the-factory-s-physi","errorCode":null,"errorMessage":"Given range's space must be in the factory's physical spaces","messagePattern":"Given range's space must be in the factory's physical spaces","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"Ghidra/Debug/ProposedUtils/src/main/java/docking/widgets/model/GAddressRangeField.java","lineNumber":183,"sourceCode":"\t\t}\n\t\trevalidateMin();\n\t\tadjustMaxToMin();\n\t}\n\n\tprotected void maxFocusLost(FocusEvent e) {\n\t\tif (factory == null) {\n\t\t\treturn;\n\t\t}\n\t\trevalidateMax();\n\t\tadjustMinToMax();\n\t}\n\n\tpublic void setRange(AddressRange range) {\n\t\tif (factory == null) {\n\t\t\tthrow new IllegalStateException(\"Must set address factory first.\");\n\t\t}\n\t\tif (!List.of(factory.getAddressSpaces()).contains(range.getAddressSpace())) {\n\t\t\tthrow new IllegalArgumentException(\n\t\t\t\t\"Given range's space must be in the factory's physical spaces\");\n\t\t}\n\t\tfieldSpace.setSelectedItem(range.getAddressSpace().getName());\n\t\tfieldMin.setText(Long.toUnsignedString(range.getMinAddress().getOffset(), 16));\n\t\tfieldMax.setText(Long.toUnsignedString(range.getMaxAddress().getOffset(), 16));\n\t}\n\n\tpublic AddressRange getRange() {\n\t\tString name = (String) fieldSpace.getSelectedItem();\n\t\tif (name == null) {\n\t\t\treturn null;\n\t\t}\n\t\tAddressSpace space = Objects.requireNonNull(factory.getAddressSpace(name));\n\t\tlong min = Long.parseUnsignedLong(fieldMin.getText(), 16);\n\t\tlong max = Long.parseUnsignedLong(fieldMax.getText(), 16);\n\t\treturn new AddressRangeImpl(space.getAddress(min), space.getAddress(max));\n\t}\n","sourceCodeStart":165,"sourceCodeEnd":201,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/Ghidra/Debug/ProposedUtils/src/main/java/docking/widgets/model/GAddressRangeField.java#L165-L201","documentation":"Thrown by GAddressRangeField.setRange() when the AddressRange's AddressSpace is not among the spaces the configured AddressFactory exposes. The widget maintains a fixed dropdown of spaces taken from the factory, so a range whose space is unknown cannot be displayed or edited. The factory must also already be set, or a different IllegalStateException fires first.","triggerScenarios":"Calling setRange(range) where range.getAddressSpace() returns a space obtained from a different Program's AddressFactory, a custom/stack/register space the factory does not list, or a space from a stale program after re-opening. Also when mixing AddressRange objects built from AddressSpace constants that differ by name from the factory's registered spaces.","commonSituations":"Reusing one program's ranges against a GAddressRangeField configured with another program's factory; passing a range built on a constant space (e.g. EXTERNAL or HASH) into a field whose factory only knows memory spaces; holding a range across a program reload where the language/compiler spec changed and space names shifted.","solutions":["Always obtain the AddressRange from the same Program whose AddressFactory was passed to setAddressFactory().","Before calling setRange, verify the space is known: Arrays.asList(factory.getAddressSpaces()).contains(range.getAddressSpace()).","If the range came from a different program, rebuild it via this factory's getAddressSpace(name).getAddress(offset).","Call setAddressFactory(program.getAddressFactory()) immediately after opening/switching the program, before any setRange call."],"exampleFix":"// before\nfield.setAddressFactory(oldProgram.getAddressFactory());\nfield.setRange(otherProgramRange); // space from other factory\n\n// after\nfield.setAddressFactory(currentProgram.getAddressFactory());\nAddressFactory f = currentProgram.getAddressFactory();\nAddressSpace sp = f.getAddressSpace(otherProgramRange.getAddressSpace().getName());\nAddressRange remapped = new AddressRangeImpl(\n    sp.getAddress(otherProgramRange.getMinAddress().getOffset()),\n    sp.getAddress(otherProgramRange.getMaxAddress().getOffset()));\nfield.setRange(remapped);","handlingStrategy":"validation","validationCode":"AddressFactory f = field.getFactory != null ? program.getAddressFactory() : null;\nAddressSpace sp = range.getAddressSpace();\nboolean known = false;\nfor (AddressSpace s : program.getAddressFactory().getAddressSpaces()) {\n  if (s.equals(sp)) { known = true; break; }\n}\nif (!known) {\n  // rebuild range in this factory's space, or skip setRange\n}\nfield.setRange(range); // only when known","typeGuard":null,"tryCatchPattern":"try {\n  field.setRange(range);\n} catch (IllegalArgumentException e) {\n  // range space not in factory; rebuild or log and skip\n  Msg.warn(this, \"Skipping range with unknown space: \" + range, e);\n}","preventionTips":["Always source AddressRange objects from the same Program whose factory backs the field.","Call setAddressFactory(program.getAddressFactory()) right after opening/switching a program.","Discard cached ranges across program reloads."],"tags":["ghidra","address-space","gui-widget","validation"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}