LMAX-Exchange/disruptor · error · IllegalArgumentException
n must be > 0
Error message
n must be > 0
What it means
Thrown by SingleProducerSequencer.tryNext(int n) when n < 1. tryNext claims n slots non-blockingly and returns InsufficientCapacityException when the ring is full; only a non-positive claim is invalid input. Same validation as the multi-producer variant, for ProducerType.SINGLE ring buffers.
Source
Thrown at src/main/java/com/lmax/disruptor/SingleProducerSequencer.java:184
/**
* @see Sequencer#tryNext()
*/
@Override
public long tryNext() throws InsufficientCapacityException
{
return tryNext(1);
}
/**
* @see Sequencer#tryNext(int)
*/
@Override
public long tryNext(final int n) throws InsufficientCapacityException
{
if (n < 1)
{
throw new IllegalArgumentException("n must be > 0");
}
if (!hasAvailableCapacity(n, true))
{
throw InsufficientCapacityException.INSTANCE;
}
long nextSequence = this.nextValue += n;
return nextSequence;
}
/**
* @see Sequencer#remainingCapacity()
*/
@Override
public long remainingCapacity()
{View on GitHub (pinned to c871ca4982)
Solutions
- Break out of the claiming loop before calling tryNext with a count < 1.
- Use the no-arg tryNext() for single-slot claims.
- Test the loop's last iteration where remaining hits zero.
Example fix
// before long seq = ringBuffer.tryNext(remaining); // remaining == 0 // after if (remaining < 1) break; long seq = ringBuffer.tryNext(remaining);
Defensive patterns
Strategy: validation
Validate before calling
if (remaining >= 1) { long seq = ringBuffer.tryNext(remaining); /* ... */ } Prevention
- Terminate claim loops when the remaining count reaches 0.
- Use tryNext() (no-arg) for single-slot claims.
When it happens
Trigger: Calling ringBuffer.tryNext(0) or tryNext(negative) on a single-producer ring — typically a claiming loop whose remaining count reaches 0 on the final iteration.
Common situations: Drain loop computes remaining = limit - claimed and calls tryNext(remaining) once too often; decrementing a shared count to 0 before the claim; batching math underflow.
Related errors
- n must be > 0
- n must be > 0 and < bufferSize
- n must be > 0 and < bufferSize
- maxBatchSize must be greater than 0
- Both batchStartsAt and batchSize must be positive but got: b
AI-assisted analysis of LMAX-Exchange/disruptor@c871ca4982 (2026-08-14).
Data as JSON: /api/errors/ff5a3927f1744452.
Report an issue: GitHub.