aeron-io/aeron · error · IllegalArgumentException

invalid length:

Error message

invalid length: 

What it means

Thrown by Publication.checkPositiveLength when a negative length is passed to an offer/tryClaim-style API. Message lengths in Aeron are int counts of payload bytes and must be non-negative; a negative value indicates a caller-side bug (bad buffer position/remaining computation, wrong offset math).

Solutions

  1. Clamp or validate the length before calling offer: reject length < 0 at the boundary where the value originates.
  2. Fix the offset/length arithmetic that produced the negative value (verify buffer.position()/remaining() after flip()).
  3. If the length comes from wire input, decode as unsigned/validated and bound-check against the buffer capacity.

Example fix

// before
publication.offer(buffer, offset, end - start); // throws when start > end

// after
int length = end - start;
if (length < 0)
{
    throw new IllegalArgumentException("computed non-positive message length: " + length);
}
publication.offer(buffer, offset, length);
Defensive patterns

Strategy: validation

Validate before calling

if (length < 0) { throw new IllegalArgumentException("length must be >= 0, got " + length); }
if (offset < 0 || offset + (long) length > buffer.capacity()) { throw new IllegalArgumentException("offset/length out of buffer bounds"); }

Type guard

boolean isValidMessageLength(int length) { return length >= 0; }

Try / catch

try
{
    publication.offer(buffer, offset, length);
}
catch (IllegalArgumentException e)
{
    // log caller-side length bug; do not retry
    log.error("bad offer length", e);
}

Prevention

When it happens

Trigger: publication.offer(buffer, offset, length) or offer of direct buffers / vectors with length < 0, typically from buffer.remaining() being negative, a bad computed offset, or unwrapped user input carrying the length.

Common situations: Passing user-supplied message sizes straight into offer(); computing length as (end - start) where start > end; using ByteBuffer.position() minus a larger mark; off-by-one after flipping buffers incorrectly.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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

Appendix: source

Thrown at aeron-client/src/main/java/io/aeron/Publication.java:690

    {
        if ((currentPosition + align(messageLength + HEADER_LENGTH, FRAME_ALIGNMENT)) >= maxPossiblePosition)
        {
            return MAX_POSITION_EXCEEDED;
        }

        if (LogBufferDescriptor.isConnected(logMetaDataBuffer))
        {
            return BACK_PRESSURED;
        }

        return NOT_CONNECTED;
    }

    final void checkPositiveLength(final int length)
    {
        if (length < 0)
        {
            throw new IllegalArgumentException("invalid length: " + length);
        }
    }

    final void checkPayloadLength(final int length)
    {
        if (length < 0)
        {
            throw new IllegalArgumentException("invalid length: " + length);
        }

        if (length > maxPayloadLength)
        {
            throw new IllegalArgumentException(
                "claim exceeds maxPayloadLength of " + maxPayloadLength + ", length=" + length);
        }
    }

    final void checkMaxMessageLength(final int length)

View on GitHub (pinned to 6d60124e15)