theonedev/onedev · error · IllegalArgumentException

Max count must be non-negative.

Error message

Max count must be non-negative.

What it means

MaxCountRevFilter.create(int) throws IllegalArgumentException when maxCount is negative. A negative limit has no meaning for 'stop after N commits', so JGit validates the argument before constructing the filter.

Source

Thrown at server-core/src/main/java/org/eclipse/jgit/revwalk/filter/MaxCountRevFilter.java:39

/**
 * Limits the number of commits output.
 */
public class MaxCountRevFilter extends RevFilter {

	private int maxCount;

	private int count;

	/**
	 * Create a new max count filter.
	 *
	 * @param maxCount
	 *            the limit
	 * @return a new filter
	 */
	public static RevFilter create(int maxCount) {
		if (maxCount < 0)
			throw new IllegalArgumentException(
					JGitText.get().maxCountMustBeNonNegative);
		return new MaxCountRevFilter(maxCount);
	}

	private MaxCountRevFilter(int maxCount) {
		this.count = 0;
		this.maxCount = maxCount;
	}

	@Override
	public boolean include(RevWalk walker, RevCommit cmit)
			throws StopWalkException, MissingObjectException,
			IncorrectObjectTypeException, IOException {
		count++;
		if (count > maxCount)
			throw StopWalkException.INSTANCE;
		return true;
	}

View on GitHub (pinned to d44925c47c)

Solutions

  1. Clamp or validate the limit before calling create: reject or coerce negatives to 0/unlimited semantics
  2. Parse numeric config with explicit range checks (>= 0)
  3. Handle 'unlimited' as absence of the filter rather than a negative count

Example fix

// before
RevFilter f = MaxCountRevFilter.create(userLimit);
// after
int limit = Math.max(0, userLimit); // or validate and reject negatives
RevFilter f = MaxCountRevFilter.create(limit);
Defensive patterns

Strategy: validation

Validate before calling

if (maxCount < 0) {
    throw new IllegalArgumentException("maxCount must be >= 0, got " + maxCount);
}

Type guard

boolean validMaxCount(int n) { return n >= 0; }

Try / catch

try {
    RevFilter f = MaxCountRevFilter.create(maxCount);
} catch (IllegalArgumentException e) {
    RevFilter f = RevFilter.NONE; // or coerce negative to 0 / unlimited handling
}

Prevention

When it happens

Trigger: Calling MaxCountRevFilter.create(-1) or any negative value — usually from an unparsed/unvalidated limit parameter or an off-by-one sentinel value.

Common situations: CLI/config limits parsed with Integer.parseInt without range checking; sentinel -1 meaning 'unlimited' passed where a non-negative count is expected (use a different mechanism for unlimited).

Related errors


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