NationalSecurityAgency/ghidra · error · IllegalStateException

Must set address factory first.

Error message

Must set address factory first.

What it means

GAddressRangeField.setRange requires that an AddressFactory has been set on the field component before a range can be assigned. The factory defines the address spaces and parsing rules needed to validate and display the range. Without it, the component cannot interpret any address or space. This is an IllegalStateException (not IllegalArgumentException) because it indicates the component was used before completing its initialization sequence.

Source

Thrown at Ghidra/Debug/ProposedUtils/src/main/java/docking/widgets/model/GAddressRangeField.java:180

	protected void minFocusLost(FocusEvent e) {
		if (factory == null) {
			return;
		}
		revalidateMin();
		adjustMaxToMin();
	}

	protected void maxFocusLost(FocusEvent e) {
		if (factory == null) {
			return;
		}
		revalidateMax();
		adjustMinToMax();
	}

	public void setRange(AddressRange range) {
		if (factory == null) {
			throw new IllegalStateException("Must set address factory first.");
		}
		if (!List.of(factory.getAddressSpaces()).contains(range.getAddressSpace())) {
			throw new IllegalArgumentException(
				"Given range's space must be in the factory's physical spaces");
		}
		fieldSpace.setSelectedItem(range.getAddressSpace().getName());
		fieldMin.setText(Long.toUnsignedString(range.getMinAddress().getOffset(), 16));
		fieldMax.setText(Long.toUnsignedString(range.getMaxAddress().getOffset(), 16));
	}

	public AddressRange getRange() {
		String name = (String) fieldSpace.getSelectedItem();
		if (name == null) {
			return null;
		}
		AddressSpace space = Objects.requireNonNull(factory.getAddressSpace(name));
		long min = Long.parseUnsignedLong(fieldMin.getText(), 16);
		long max = Long.parseUnsignedLong(fieldMax.getText(), 16);

View on GitHub (pinned to d5f144c24d)

Solutions

  1. Call setFactory(factory) before setRange(range)
  2. Set the factory in the panel/dialog initialization method before any range operations
  3. Use a builder or initialization helper that enforces the factory-first ordering
  4. If unsure whether the factory is set, guard: if (field.getFactory() != null) field.setRange(range)

Example fix

// before
GAddressRangeField field = new GAddressRangeField();
field.setRange(range); // throws: no factory
// after
GAddressRangeField field = new GAddressRangeField();
field.setFactory(addressFactory);
field.setRange(range);
Defensive patterns

Strategy: validation

Validate before calling

boolean isFieldInitialized(GAddressRangeField field) {
    // Check factory is set before calling setRange
    return field.getFactory() != null;
}

// Guarded call:
if (field.getFactory() != null) {
    field.setRange(range);
}

Type guard

// N/A — GAddressRangeField is a single type; check initialization state

Try / catch

try {
    field.setRange(range);
} catch (IllegalStateException e) {
    field.setFactory(factory);
    field.setRange(range);
}

Prevention

When it happens

Trigger: Calling setRange(range) on a GAddressRangeField instance before calling setFactory(factory). The factory field is null and the guard at line 179 detects this.

Common situations: Building a UI dialog or panel that constructs the field and immediately sets a range in the constructor before the factory is wired. Using a field from a reused component where the factory was cleared. Initializing fields in the wrong order during panel setup.

Related errors


AI-assisted analysis of NationalSecurityAgency/ghidra@d5f144c24d (2026-08-14). Data as JSON: /api/errors/1060a7b91496ef49. Report an issue: GitHub.