aeron-io/aeron · error · IllegalArgumentException

lengthOne < 0

Error message

lengthOne < 0: {lengthOne}

What it means

Thrown by the static Publication.validateAndComputeLength when lengthOne is negative. This helper validates the two lengths given to offer of two buffers (vectored offer) and computes their combined total; negative components are rejected before any total is computed.

Solutions

  1. Validate lengthOne >= 0 at the call site before invoking the vectored offer.
  2. Fix the buffer position/limit arithmetic that produced the negative first length (flip() read-mode buffers before measuring).
  3. If lengths come from computed (start, end) pairs, assert start <= end before subtracting.

Example fix

// before
publication.offer(header, 0, headerLen, body, 0, bodyLen); // headerLen negative

// after
if (headerLen < 0 || bodyLen < 0)
{
    throw new IllegalArgumentException("negative vectored length");
}
publication.offer(header, 0, headerLen, body, 0, bodyLen);
Defensive patterns

Strategy: validation

Validate before calling

if (lengthOne < 0 || lengthTwo < 0) { throw new IllegalArgumentException("negative vectored length"); }

Type guard

boolean isValidVectoredLengths(int lengthOne, int lengthTwo) { return lengthOne >= 0 && lengthTwo >= 0; }

Try / catch

try
{
    publication.offer(buf1, off1, len1, buf2, off2, len2);
}
catch (IllegalArgumentException e)
{
    // negative component length; fix buffer arithmetic before retrying
    log.error("invalid vectored offer", e);
}

Prevention

When it happens

Trigger: publication.offer(bufferOne, offsetOne, lengthOne, bufferTwo, offsetTwo, lengthTwo) with lengthOne < 0 — usually from incorrect offset arithmetic or negative remaining() on the first buffer.

Common situations: Header+payload vectored writes where the header buffer's computed length went negative (mark/reset mistakes, un-flipped ByteBuffer); programmatic assembly of message parts with miscomputed sizes.

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/24692b11e2f9e55b. Report an issue: GitHub.

Appendix: source

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

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

    final void checkMaxMessageLength(final int length)
    {
        if (length > maxMessageLength)
        {
            throw new IllegalArgumentException(
                "message exceeds maxMessageLength of " + maxMessageLength + ", length=" + length);
        }
    }

    static int validateAndComputeLength(final int lengthOne, final int lengthTwo)
    {
        if (lengthOne < 0)
        {
            throw new IllegalArgumentException("lengthOne < 0: " + lengthOne);
        }

        if (lengthTwo < 0)
        {
            throw new IllegalArgumentException("lengthTwo < 0: " + lengthTwo);
        }

        final int totalLength = lengthOne + lengthTwo;
        if (totalLength < 0)
        {
            throw new IllegalArgumentException("overflow totalLength=" + totalLength);
        }

        return totalLength;
    }

    /**
     * Returns a string representation of a position. Generally used for errors. If the position is a valid error then

View on GitHub (pinned to 6d60124e15)