NationalSecurityAgency/ghidra · error · IllegalArgumentException
min must precede max
Error message
min must precede max
What it means
DBTraceUtils.toRange(min, max) constructs an AddressRange after validating endpoint ordering. It throws IllegalArgumentException("min must precede max") when min.compareTo(max) > 0, i.e. min is strictly greater than max. Equality is allowed (produces a single-address range). This is a precondition guard ensuring the range is well-formed before delegating to AddressRangeImpl, which itself assumes min <= max.
Source
Thrown at Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/database/DBTraceUtils.java:512
if (forward) {
Address max = all.getMaxAddress();
return factory.getAddressSet(start, max);
}
Address min = all.getMinAddress();
return factory.getAddressSet(min, start);
}
/**
* Create an address range, checking the endpoints
*
* @param min the min address, which must be less than or equal to max
* @param max the max address, which must be greater than or equal to min
* @return the range
* @throws IllegalArgumentException if max is less than min
*/
public static AddressRange toRange(Address min, Address max) {
if (min.compareTo(max) > 0) {
throw new IllegalArgumentException("min must precede max");
}
return new AddressRangeImpl(min, max);
}
}
View on GitHub (pinned to d5f144c24d)
Solutions
- Normalize the two addresses before calling: assign the smaller to min via a.compareTo(b) > 0 swap.
- If you only have logical from/to that may be reversed, swap them explicitly when from.compareTo(to) > 0.
- Guard the call site: if (a.compareTo(b) > 0) handle the degenerate/empty case instead of calling toRange.
Example fix
// before
AddressRange r = DBTraceUtils.toRange(start, end);
// after
if (start.compareTo(end) > 0) {
Address t = start; start = end; end = t;
}
AddressRange r = DBTraceUtils.toRange(start, end); Defensive patterns
Strategy: validation
Validate before calling
static AddressRange safeRange(Address a, Address b) {
if (a.compareTo(b) > 0) { Address t = a; a = b; b = t; }
return DBTraceUtils.toRange(a, b);
} Prevention
- Always derive min/max via compareTo rather than assuming call-site order.
- Treat from/to as unordered selection bounds and normalize before constructing a range.
- Unit-test range construction with reversed and equal endpoints.
When it happens
Trigger: Calling DBTraceUtils.toRange(Address, Address) where the first argument's compareTo is greater than the second. Happens when min/max are swapped, when selection bounds come back reversed (user dragged a selection backwards), or when the two addresses belong to address spaces whose cross-space compareTo ordering is unexpected.
Common situations: Plugins deriving ranges from cursor/selection where start can be after end; snapshot/loop code that computes from/to in the wrong order; passing addresses from distinct address spaces (overlay vs base) where the comparison surprises the caller.
Related errors
- length < 0
- Must set address factory first.
- Sleigh language required
- Emulation requires a Sleigh language
- Must save breakpoint to program before naming it
AI-assisted analysis of NationalSecurityAgency/ghidra@d5f144c24d (2026-08-14).
Data as JSON: /api/errors/e7fc668094313445.
Report an issue: GitHub.