theonedev/onedev · error · IllegalStateException

Output has already been started.

Error message

Output has already been started.

What it means

Several RevWalk configuration methods (e.g. revSort, setTreeFilter, setRewriteParents, markStart-adjacent setup) call assertNotStarted(), which throws IllegalStateException once the walk has begun producing output (pending is no longer a StartGenerator). Configuration is immutable after iteration starts so in-flight generators are not invalidated.

Source

Thrown at server-core/src/main/java/org/eclipse/jgit/revwalk/RevWalk.java:1726

				RevCommit r = next;
				next = nextForIterator();
				return r;
			}

			@Override
			public void remove() {
				throw new UnsupportedOperationException();
			}
		};
	}

	/**
	 * Throws an exception if we have started producing output.
	 */
	protected void assertNotStarted() {
		if (isNotStarted())
			return;
		throw new IllegalStateException(
				JGitText.get().outputHasAlreadyBeenStarted);
	}

	/**
	 * Throws an exception if any commits have been marked as start.
	 * <p>
	 * If {@link #markStart(RevCommit)} has already been called,
	 * {@link #reset()} can be called to satisfy this condition.
	 *
	 * @since 5.5
	 */
	protected void assertNoCommitsMarkedStart() {
		if (roots.isEmpty())
			return;
		throw new IllegalStateException(
				JGitText.get().commitsHaveAlreadyBeenMarkedAsStart);
	}

View on GitHub (pinned to d44925c47c)

Solutions

  1. Apply all filters, sorting and marking before the first next()/iterator() call.
  2. Create a new RevWalk for each traversal instead of reconfiguring a started one.
  3. Ensure no code path iterates (e.g. size/count helpers, stream().count()) before configuration completes.

Example fix

// before
walk.markStart(head);
walk.next();
walk.sort(RevSort.REVERSE); // IllegalStateException
// after
walk.sort(RevSort.REVERSE);
walk.markStart(head);
walk.next();
Defensive patterns

Strategy: validation

Validate before calling

if (!walk.isNotStarted())
    throw new IllegalStateException("configure the RevWalk before iterating");
walk.sort(RevSort.COMMIT_TIME_DESC);

Type guard

boolean isConfigurable(RevWalk w) { return w.isNotStarted(); } // package-private; emulate by configuring before markStart

Try / catch

try {
    walk.setRevFilter(filter);
} catch (IllegalStateException e) {
    walk = new RevWalk(repo); // fresh walk, reconfigure from scratch
    walk.setRevFilter(filter);
}

Prevention

When it happens

Trigger: Calling revSort/setTreeFilter/filter/setRevFilter etc. after iterating the walk (even partially), after markStart, or reconfiguring a reused walk between traversals without resetting the generator state appropriately.

Common situations: Reusing a single RevWalk across requests and applying new filters after the first traversal; setting sort order inside a loop after calling next(); configuring in a finally block by mistake.

Understand the failure class

Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.

Related errors


AI-assisted analysis of theonedev/onedev@d44925c47c (2026-09-06). Data as JSON: /api/errors/32cca0bfceeffbb4. Report an issue: GitHub.