NationalSecurityAgency/ghidra · error · IllegalArgumentException
Cannot rewind a negative number
Error message
Cannot rewind a negative number
What it means
Sequence.rewind throws when called with a negative count. Rewinding means removing the given number of steps from the end of the sequence; a negative count is logically meaningless. The method modifies the sequence in place, reducing each step's tick count from the tail until the requested count is consumed.
Source
Thrown at Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/model/time/schedule/Sequence.java:188
for (; toRemove > 0; toRemove--) {
steps.remove(steps.size() - 1);
}
}
/**
* Rewind this sequence the given step count
*
* <p>
* This modifies the sequence in place, removing the given count from the end of the sequence.
* Any step whose count is reduced to 0 as a result of rewinding is removed entirely from the
* sequence. Note that each sleigh step (modification) counts as one step when rewinding.
*
* @param count the step count to rewind
* @return if count exceeds the steps of this sequence, the (positive) difference remaining
*/
public long rewind(long count) {
if (count < 0) {
throw new IllegalArgumentException("Cannot rewind a negative number");
}
while (!steps.isEmpty()) {
int lastIndex = steps.size() - 1;
count = steps.get(lastIndex).rewind(count);
if (count >= 0) {
steps.remove(lastIndex);
}
if (count <= 0) {
break;
}
}
return Long.max(0, count);
}
/**
* Drop the last step from this sequence
*
* @return the sequence with the last step removedView on GitHub (pinned to d5f144c24d)
Solutions
- Clamp the count to zero before calling: rewind(Math.max(0, count))
- Check the sign before calling: if (count >= 0) sequence.rewind(count)
- If computing a delta between two sequences, ensure the result is non-negative or use Long.max(0, delta)
Example fix
// before
sequence.rewind(delta); // delta may be negative
// after
if (delta > 0) {
sequence.rewind(delta);
} Defensive patterns
Strategy: validation
Validate before calling
long safeCount = Math.max(0, requestedCount);
if (safeCount > 0) {
sequence.rewind(safeCount);
} Type guard
// N/A — primitive long, guard with range check
Try / catch
try {
sequence.rewind(count);
} catch (IllegalArgumentException e) {
// clamp count to 0 and retry, or report
sequence.rewind(0);
} Prevention
- Always clamp computed rewind counts with Math.max(0, delta)
- When diffing two schedules, verify the direction before rewinding
- Treat negative rewind as a no-op rather than passing it through
When it happens
Trigger: Calling sequence.rewind(negativeNumber) directly, or calling it with a value computed from a subtraction that can go negative (e.g. rewind(this.getTotalTickCount() - other.getTotalTickCount()) when this has fewer ticks than other).
Common situations: Diffing two schedules and rewinding by the delta without clamping to zero. Using rewind in a loop where the count variable is decremented past zero by external logic.
Related errors
- The given prefix (%s) is not actually a prefix of this (%s).
- Thread must be given, e.g., 0:t1-3, since the last thread or
- Thread with key %d does not exist in given trace
- Cannot have instructions steps following p-code steps
- Cannot parse step: '
AI-assisted analysis of NationalSecurityAgency/ghidra@d5f144c24d (2026-08-14).
Data as JSON: /api/errors/9d369fb549c24818.
Report an issue: GitHub.