aeron-io/aeron · error · IllegalArgumentException

invalid input: captureLength=

Error message

invalid input: captureLength=${captureLength}, length=${length}

What it means

CommonEventEncoder.internalEncodeLogHeader validates the capture-length parameters before writing an event-log header. captureLength must be non-negative, no greater than the full record length, and no greater than MAX_CAPTURE_LENGTH. Passing any value outside that range throws IllegalArgumentException, meaning the caller computed an invalid capture size.

Solutions

  1. Clamp captureLength: Math.min(length, MAX_CAPTURE_LENGTH) and ensure >= 0 before calling encodeLogHeader.
  2. Check the configuration/source of captureLength (often a system property) for a bad value.
  3. Ensure length reflects the actual encoded record size, not buffer capacity.
  4. Guard the caller with a validation step and skip logging when invalid.

Example fix

// before
encoder.encodeLogHeader(buffer, captureLength, length, clock); // captureLength may exceed length
// after
final int safeCapture = Math.min(Math.max(captureLength, 0), Math.min(length, CommonEventEncoder.MAX_CAPTURE_LENGTH));
encoder.encodeLogHeader(buffer, safeCapture, length, clock);
Defensive patterns

Strategy: validation

Validate before calling

static boolean isValidCaptureParams(final int captureLength, final int length)
{
    return captureLength >= 0
        && captureLength <= length
        && captureLength <= CommonEventEncoder.MAX_CAPTURE_LENGTH;
}
// call encodeLogHeader only if isValidCaptureParams(captureLength, length)

Try / catch

try
{
    CommonEventEncoder.encodeLogHeader(buffer, captureLength, length, clock);
}
catch (final IllegalArgumentException ex)
{
    LOGGER.error("bad log header params", ex);
}

Prevention

When it happens

Trigger: Calling encodeLogHeader with captureLength < 0; captureLength exceeding the record length; captureLength exceeding MAX_CAPTURE_LENGTH (e.g. passing the full buffer length when it exceeds the capture cap).

Common situations: Custom event logger implementations computing min() incorrectly; misconfigured capture-length system properties; passing buffer capacity instead of record length.

Related errors


AI-assisted analysis of aeron-io/aeron@6d60124e15 (2026-09-12). Data as JSON: /api/errors/166a30b862c2aa2c. Report an issue: GitHub.

Appendix: source

Thrown at aeron-client/src/main/java/io/aeron/logging/CommonEventEncoder.java:80

     * @param length         original length.
     * @return header length in bytes.
     */
    public static int encodeLogHeader(
        final MutableDirectBuffer encodingBuffer, final int offset, final int captureLength, final int length)
    {
        return internalEncodeLogHeader(encodingBuffer, offset, captureLength, length, SystemNanoClock.INSTANCE);
    }

    static int internalEncodeLogHeader(
        final MutableDirectBuffer encodingBuffer,
        final int offset,
        final int captureLength,
        final int length,
        final NanoClock nanoClock)
    {
        if (captureLength < 0 || captureLength > length || captureLength > MAX_CAPTURE_LENGTH)
        {
            throw new IllegalArgumentException("invalid input: captureLength=" + captureLength + ", length=" + length);
        }

        int encodedLength = 0;
        /*
         * Stream of values:
         * - capture buffer length (int)
         * - total buffer length (int)
         * - timestamp (long)
         * - buffer (until end)
         */

        encodingBuffer.putInt(offset + encodedLength, captureLength, LITTLE_ENDIAN);
        encodedLength += SIZE_OF_INT;

        encodingBuffer.putInt(offset + encodedLength, length, LITTLE_ENDIAN);
        encodedLength += SIZE_OF_INT;

        encodingBuffer.putLong(offset + encodedLength, nanoClock.nanoTime(), LITTLE_ENDIAN);

View on GitHub (pinned to 6d60124e15)