{"record":{"id":"de42302a3375230c","repo":"aeron-io/aeron","slug":"invalid-length","errorCode":null,"errorMessage":"invalid length: ","messagePattern":"invalid length: ","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"aeron-client/src/main/java/io/aeron/Publication.java","lineNumber":690,"sourceCode":"    {\n        if ((currentPosition + align(messageLength + HEADER_LENGTH, FRAME_ALIGNMENT)) >= maxPossiblePosition)\n        {\n            return MAX_POSITION_EXCEEDED;\n        }\n\n        if (LogBufferDescriptor.isConnected(logMetaDataBuffer))\n        {\n            return BACK_PRESSURED;\n        }\n\n        return NOT_CONNECTED;\n    }\n\n    final void checkPositiveLength(final int length)\n    {\n        if (length < 0)\n        {\n            throw new IllegalArgumentException(\"invalid length: \" + length);\n        }\n    }\n\n    final void checkPayloadLength(final int length)\n    {\n        if (length < 0)\n        {\n            throw new IllegalArgumentException(\"invalid length: \" + length);\n        }\n\n        if (length > maxPayloadLength)\n        {\n            throw new IllegalArgumentException(\n                \"claim exceeds maxPayloadLength of \" + maxPayloadLength + \", length=\" + length);\n        }\n    }\n\n    final void checkMaxMessageLength(final int length)","sourceCodeStart":672,"sourceCodeEnd":708,"githubUrl":"https://github.com/aeron-io/aeron/blob/6d60124e15e35c11b49ba2e3c2c2858a09a18803/aeron-client/src/main/java/io/aeron/Publication.java#L672-L708","documentation":"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).","triggerScenarios":"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.","commonSituations":"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.","solutions":["Clamp or validate the length before calling offer: reject length < 0 at the boundary where the value originates.","Fix the offset/length arithmetic that produced the negative value (verify buffer.position()/remaining() after flip()).","If the length comes from wire input, decode as unsigned/validated and bound-check against the buffer capacity."],"exampleFix":"// before\npublication.offer(buffer, offset, end - start); // throws when start > end\n\n// after\nint length = end - start;\nif (length < 0)\n{\n    throw new IllegalArgumentException(\"computed non-positive message length: \" + length);\n}\npublication.offer(buffer, offset, length);","handlingStrategy":"validation","validationCode":"if (length < 0) { throw new IllegalArgumentException(\"length must be >= 0, got \" + length); }\nif (offset < 0 || offset + (long) length > buffer.capacity()) { throw new IllegalArgumentException(\"offset/length out of buffer bounds\"); }","typeGuard":"boolean isValidMessageLength(int length) { return length >= 0; }","tryCatchPattern":"try\n{\n    publication.offer(buffer, offset, length);\n}\ncatch (IllegalArgumentException e)\n{\n    // log caller-side length bug; do not retry\n    log.error(\"bad offer length\", e);\n}","preventionTips":["Flip ByteBuffers to read mode before measuring with remaining().","Derive lengths from position/limit arithmetic, never from user input unvalidated.","Assert start <= end wherever lengths are computed as differences.","Add boundary unit tests for offset/length computation helpers."],"tags":["aeron","publication","argument-validation","messaging"],"backgroundTag":"invalid-argument-value","analyzedSha":"6d60124e15e35c11b49ba2e3c2c2858a09a18803","analyzedAt":"2026-09-12T11:17:07.683Z","contentChangedAt":"2026-09-12T11:17:07.683Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}