{"record":{"id":"79315e4986ec024b","repo":"aeron-io/aeron","slug":"invalid-length-length","errorCode":null,"errorMessage":"invalid length: \" + length","messagePattern":"invalid length: \" \\+ length","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"aeron-archive/src/main/java/io/aeron/archive/RecordingReader.java","lineNumber":70,"sourceCode":"\n    private final long replayLimit;\n    private long replayPosition;\n    private long segmentFilePosition;\n    private int termOffset;\n    private int termBaseSegmentOffset;\n    private boolean isDone = false;\n\n    RecordingReader(\n        final RecordingSummary recordingSummary, final File archiveDir, final long position, final long length)\n    {\n        if (position < NULL_POSITION)\n        {\n            throw new IllegalArgumentException(\"invalid position: \" + position);\n        }\n\n        if (length < NULL_LENGTH)\n        {\n            throw new IllegalArgumentException(\"invalid length: \" + length);\n        }\n\n        this.archiveDir = archiveDir;\n        this.termLength = recordingSummary.termBufferLength;\n        this.segmentLength = recordingSummary.segmentFileLength;\n        this.recordingId = recordingSummary.recordingId;\n\n        final long startPosition = recordingSummary.startPosition;\n        final long fromPosition = position == NULL_POSITION ? startPosition : position;\n        final long maxLength = recordingSummary.stopPosition != NULL_POSITION ?\n            recordingSummary.stopPosition - fromPosition : Long.MAX_VALUE - fromPosition;\n\n        final long replayLength = length == NULL_LENGTH ? maxLength : Math.min(length, maxLength);\n        if (replayLength < 0)\n        {\n            throw new IllegalArgumentException(\"length must be positive\");\n        }\n","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/aeron-io/aeron/blob/6d60124e15e35c11b49ba2e3c2c2858a09a18803/aeron-archive/src/main/java/io/aeron/archive/RecordingReader.java#L52-L88","documentation":"RecordingReader also validates the requested replay length. A length below NULL_LENGTH (a negative value other than the null sentinel) is meaningless, so the constructor throws IllegalArgumentException.","triggerScenarios":"Constructing RecordingReader with length < NULL_LENGTH — a negative length passed through a replay request instead of NULL_LENGTH (-1, meaning 'to the end of the recording') or a positive byte count.","commonSituations":"Client computes replay length as stopPosition - startPosition with a reversed order; sending a negative length in a replay request message; confusing NULL_LENGTH with other sentinel values.","solutions":["Use Aeron.NULL_LENGTH (-1) to request replay to the end of the recording.","Ensure length is either NULL_LENGTH or a positive byte count; clamp negatives in client code.","Check stop/start subtraction order when computing explicit replay lengths.","Validate the replay request fields before sending them to the archive."],"exampleFix":"// before\nlong length = stopPos - startPos; // stopPos < startPos -> negative\n// after\nlong length = stopPos >= startPos ? stopPos - startPos : Aeron.NULL_LENGTH;","handlingStrategy":"validation","validationCode":"if (length != Aeron.NULL_LENGTH && length < 0) {\n    throw new IllegalArgumentException(\"length must be Aeron.NULL_LENGTH or positive\");\n}","typeGuard":null,"tryCatchPattern":"try { replay(recId, position, length); }\ncatch (IllegalArgumentException e) {\n    if (e.getMessage().startsWith(\"invalid length\")) { clampLengthAndRetry(); }\n}","preventionTips":["Use Aeron.NULL_LENGTH for 'replay to end'.","Check subtraction order when computing explicit lengths from stop/start positions.","Clamp computed lengths to >= 0 before issuing replay requests."],"tags":["replay","invalid-argument","length","archive"],"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"}