{"record":{"id":"24692b11e2f9e55b","repo":"aeron-io/aeron","slug":"lengthone-0-lengthone","errorCode":null,"errorMessage":"lengthOne < 0: {lengthOne}","messagePattern":"lengthOne < 0: (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"aeron-client/src/main/java/io/aeron/Publication.java","lineNumber":721,"sourceCode":"            throw new IllegalArgumentException(\n                \"claim exceeds maxPayloadLength of \" + maxPayloadLength + \", length=\" + length);\n        }\n    }\n\n    final void checkMaxMessageLength(final int length)\n    {\n        if (length > maxMessageLength)\n        {\n            throw new IllegalArgumentException(\n                \"message exceeds maxMessageLength of \" + maxMessageLength + \", length=\" + length);\n        }\n    }\n\n    static int validateAndComputeLength(final int lengthOne, final int lengthTwo)\n    {\n        if (lengthOne < 0)\n        {\n            throw new IllegalArgumentException(\"lengthOne < 0: \" + lengthOne);\n        }\n\n        if (lengthTwo < 0)\n        {\n            throw new IllegalArgumentException(\"lengthTwo < 0: \" + lengthTwo);\n        }\n\n        final int totalLength = lengthOne + lengthTwo;\n        if (totalLength < 0)\n        {\n            throw new IllegalArgumentException(\"overflow totalLength=\" + totalLength);\n        }\n\n        return totalLength;\n    }\n\n    /**\n     * Returns a string representation of a position. Generally used for errors. If the position is a valid error then","sourceCodeStart":703,"sourceCodeEnd":739,"githubUrl":"https://github.com/aeron-io/aeron/blob/6d60124e15e35c11b49ba2e3c2c2858a09a18803/aeron-client/src/main/java/io/aeron/Publication.java#L703-L739","documentation":"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.","triggerScenarios":"publication.offer(bufferOne, offsetOne, lengthOne, bufferTwo, offsetTwo, lengthTwo) with lengthOne < 0 — usually from incorrect offset arithmetic or negative remaining() on the first buffer.","commonSituations":"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.","solutions":["Validate lengthOne >= 0 at the call site before invoking the vectored offer.","Fix the buffer position/limit arithmetic that produced the negative first length (flip() read-mode buffers before measuring).","If lengths come from computed (start, end) pairs, assert start <= end before subtracting."],"exampleFix":"// before\npublication.offer(header, 0, headerLen, body, 0, bodyLen); // headerLen negative\n\n// after\nif (headerLen < 0 || bodyLen < 0)\n{\n    throw new IllegalArgumentException(\"negative vectored length\");\n}\npublication.offer(header, 0, headerLen, body, 0, bodyLen);","handlingStrategy":"validation","validationCode":"if (lengthOne < 0 || lengthTwo < 0) { throw new IllegalArgumentException(\"negative vectored length\"); }","typeGuard":"boolean isValidVectoredLengths(int lengthOne, int lengthTwo) { return lengthOne >= 0 && lengthTwo >= 0; }","tryCatchPattern":"try\n{\n    publication.offer(buf1, off1, len1, buf2, off2, len2);\n}\ncatch (IllegalArgumentException e)\n{\n    // negative component length; fix buffer arithmetic before retrying\n    log.error(\"invalid vectored offer\", e);\n}","preventionTips":["Flip both buffers to read mode before computing component lengths.","Validate header and payload lengths immediately after computing them.","Use a single helper that measures buffer slices safely.","Unit-test vectored offers with header+payload combinations."],"tags":["aeron","publication","vectored-offer","argument-validation"],"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"}