MyCATApache/Mycat-Server · error · IllegalArgumentException
A batchSize of: with batchStatsAt of: will overrun the…
Error message
A batchSize of: ${batchSize} with batchStatsAt of: ${batchStartsAt} will overrun the available number of arguments: ${available} What it means
batchOverRuns verifies that a batch publish request does not ask for more translator arguments than the supplied argument array actually holds. When batchStartsAt + batchSize exceeds arg0.length, the call would read past the end of the array, so IllegalArgumentException is thrown with the remaining argument count in the message.
Solutions
- Clamp batchSize to translators.length - batchStartsAt before the call.
- Verify batchStartsAt is the intended offset and that the array contains all expected elements.
- Pass the full array with batchStartsAt=0 and batchSize=translators.length when publishing everything.
- Add an assertion/unit test covering the offset+size arithmetic.
Example fix
// before ring.publishEvents(translators, 5, 8); // overrun // after int start = 5; int size = Math.min(8, translators.length - start); ring.publishEvents(translators, start, size);
Defensive patterns
Strategy: validation
Validate before calling
public static void checkBatch(Object[] args, int batchStartsAt, int batchSize) {
if (batchStartsAt < 0 || batchSize < 0 || batchStartsAt + batchSize > args.length)
throw new IllegalArgumentException("batch out of bounds: start=" + batchStartsAt + " size=" + batchSize + " len=" + args.length);
} Try / catch
try {
ring.publishEvents(translators, start, size);
} catch (IllegalArgumentException e) {
logger.warn("batch overrun, clamping", e);
ring.publishEvents(translators, start, translators.length - start);
} Prevention
- Clamp batchSize to array.length - batchStartsAt before every call
- Unit-test offset/size arithmetic for boundary conditions
- Prefer the whole-array publishEvents(translators) overload when no slicing is needed
When it happens
Trigger: Calling RingBuffer batch publish APIs (e.g. publishEvents(translators, batchStartsAt, batchSize)) where batchStartsAt + batchSize > translators.length, e.g. 10 translators with batchStartsAt=5, batchSize=8.
Common situations: Off-by-one errors when slicing an array of event translators, computing batchSize from a list size but a different offset, or reusing a batch size constant after changing array contents.
Related errors
- Both batchStartsAt and batchSize must be positive but got…
- The ring buffer cannot accommodate
- bufferSize must not be less than 1
- bufferSize must be a power of 2
- bufferSize must not be less than 1
AI-assisted analysis of MyCATApache/Mycat-Server@65f8d8beb7 (2026-09-11).
Data as JSON: /api/errors/2d937b4f989e8648.
Report an issue: GitHub.
Appendix: source
Thrown at src/main/java/io/mycat/memory/unsafe/ringbuffer/RingBuffer.java:270
@Override
public boolean tryPublishEvent(EventTranslatorVararg<E> translator, Object... args) {
try {
final long sequence = sequencer.tryNext();
translateAndPublish(translator, sequence, args);
return true;
} catch (InsufficientCapacityException e) {
return false;
}
}
private void checkBounds(final EventTranslator<E>[] translators, final int batchStartsAt, final int batchSize) {
checkBatchSizing(batchStartsAt, batchSize);
batchOverRuns(translators, batchStartsAt, batchSize);
}
private <A> void batchOverRuns(final A[] arg0, final int batchStartsAt, final int batchSize) {
if (batchStartsAt + batchSize > arg0.length) {
throw new IllegalArgumentException(
"A batchSize of: " + batchSize +
" with batchStatsAt of: " + batchStartsAt +
" will overrun the available number of arguments: " + (arg0.length - batchStartsAt));
}
}
private void checkBatchSizing(int batchStartsAt, int batchSize) {
if (batchStartsAt < 0 || batchSize < 0) {
throw new IllegalArgumentException("Both batchStartsAt and batchSize must be positive but got: batchStartsAt " + batchStartsAt + " and batchSize " + batchSize);
} else if (batchSize > bufferSize) {
throw new IllegalArgumentException("The ring buffer cannot accommodate " + batchSize + " it only has space for " + bufferSize + " entities.");
}
}
/**
* @see io.mycat.memory.unsafe.ringbuffer.common.event.EventSink#publishEvent(EventTranslator)
*/
@OverrideView on GitHub (pinned to 65f8d8beb7)