NationalSecurityAgency/ghidra · error · IllegalArgumentException

Cannot rewind a negative number

Error message

Cannot rewind a negative number

What it means

Thrown by AbstractStep.rewind(long steps) when steps < 0. rewind() only reduces a step's tick count (clamped at 0), so a negative argument is rejected; use advance() to grow the count.

Source

Thrown at Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/model/time/schedule/AbstractStep.java:98

	 * Add to the count of this step
	 * 
	 * @param steps the count to add
	 */
	public void advance(long steps) {
		if (steps < 0) {
			throw new IllegalArgumentException("Cannot advance a negative number");
		}
		long newCount = tickCount + steps;
		if (newCount < 0) {
			throw new IllegalArgumentException("Total step count exceeds LONG_MAX");
		}
		this.tickCount = newCount;
	}

	@Override
	public long rewind(long steps) {
		if (steps < 0) {
			throw new IllegalArgumentException("Cannot rewind a negative number");
		}
		long diff = this.tickCount - steps;
		this.tickCount = Long.max(0, diff);
		return -diff;
	}

	@Override
	public boolean isCompatible(Step step) {
		if (!(step.getClass() == this.getClass())) {
			return false;
		}
		AbstractStep as = (AbstractStep) step;
		return this.threadKey == as.threadKey || as.threadKey == -1;
	}

	@Override
	public void addTo(Step step) {
		assert isCompatible(step);

View on GitHub (pinned to d5f144c24d)

Solutions

  1. Route growth through advance(): if (steps >= 0) rewind(steps); else advance(-steps).
  2. Guarantee the value passed to rewind is non-negative.
  3. Use higher-level schedule APIs that pick advance vs rewind from the sign.

Example fix

// before
step.rewind(delta); // delta < 0 -> exception

// after
if (delta >= 0) step.rewind(delta);
else step.advance(-delta);
Defensive patterns

Strategy: validation

Validate before calling

if (delta >= 0) step.rewind(delta);
else step.advance(-delta);

Type guard

static boolean validRewind(long steps) { return steps >= 0; }

Prevention

When it happens

Trigger: Calling step.rewind(n) with n < 0, e.g. passing a signed delta straight into rewind.

Common situations: Reusing a signed delta for both directions; schedule arithmetic where the delta's sign was not normalized.

Related errors


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