{"record":{"id":"dbfe219c3c939295","repo":"apache/maven","slug":"queue-and-batch-sizes-must-be-greater-than-1","errorCode":null,"errorMessage":"Queue and batch sizes must be greater than 1","messagePattern":"Queue and batch sizes must be greater than 1","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"compat/maven-embedder/src/main/java/org/apache/maven/cli/transfer/SimplexTransferListener.java","lineNumber":74,"sourceCode":"     * Constructor that makes passed in delegate run on single thread, and will block on last event.\n     */\n    public SimplexTransferListener(TransferListener delegate) {\n        this(delegate, QUEUE_SIZE, BATCH_MAX_SIZE, true);\n    }\n\n    /**\n     * Constructor that may alter behaviour of this listener.\n     *\n     * @param delegate The delegate that should run on single thread.\n     * @param queueSize The event queue size (default {@code 1024}).\n     * @param batchMaxSize The maximum batch size delegate should receive (default {@code 500}).\n     * @param blockOnLastEvent Should this listener block on last transfer end (completed or corrupted) block? (default {@code true}).\n     */\n    public SimplexTransferListener(\n            TransferListener delegate, int queueSize, int batchMaxSize, boolean blockOnLastEvent) {\n        this.delegate = requireNonNull(delegate);\n        if (queueSize < 1 || batchMaxSize < 1) {\n            throw new IllegalArgumentException(\"Queue and batch sizes must be greater than 1\");\n        }\n        this.batchMaxSize = batchMaxSize;\n        this.blockOnLastEvent = blockOnLastEvent;\n\n        this.eventQueue = new ArrayBlockingQueue<>(queueSize);\n        Thread updater = new Thread(this::feedConsumer);\n        updater.setDaemon(true);\n        updater.start();\n    }\n\n    public TransferListener getDelegate() {\n        return delegate;\n    }\n\n    private void feedConsumer() {\n        final ArrayList<Exchange> batch = new ArrayList<>(batchMaxSize);\n        try {\n            while (true) {","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/apache/maven/blob/e4093d4e120eac99d6bdce5ba67cace2f3085c97/compat/maven-embedder/src/main/java/org/apache/maven/cli/transfer/SimplexTransferListener.java#L56-L92","documentation":"SimplexTransferListener is the async transfer-event listener Maven wraps around progress displays (console download output). Its four-argument constructor validates queueSize and batchMaxSize: if either is < 1 it throws IllegalArgumentException 'Queue and batch sizes must be greater than 1'. (Wording is slightly off — the check actually rejects only values below 1, so exactly 1 is accepted.) The two-argument/convenience constructor uses defaults 1024/500; this error requires programmatic instantiation with bad values.","triggerScenarios":"Constructing new SimplexTransferListener(delegate, 0, 500, true), passing a batch size of 0, or computing sizes from configuration/capacity math that rounds down to zero (e.g. queue = total/branches with small inputs, or Integer.parseInt of an empty string defaulting via a ternary to 0).","commonSituations":"Custom Maven embedders or forks constructing the listener from externalized config where a missing key maps to 0. Test harnesses probing constructor validation. Refactors that changed a default from 1024 to a computed expression.","solutions":["Pass values >= 1; keep the proven defaults queueSize=1024, batchMaxSize=500 unless you have measured a reason to change them.","Clamp derived values: Math.max(1, computed) before calling the constructor.","Validate external config at load time and reject missing/zero entries with a clear message instead of letting the constructor throw.","For low-volume scenarios, remember batchMaxSize only caps batching — small values are legal and cheap; only < 1 is fatal."],"exampleFix":"// before\nint queue = config.getInt(\"transfer.queue\", 0);\nnew SimplexTransferListener(delegate, queue, 0, true);\n\n// after\nint queue = Math.max(1, config.getInt(\"transfer.queue\", 1024));\nint batch = Math.max(1, config.getInt(\"transfer.batch\", 500));\nnew SimplexTransferListener(delegate, queue, batch, true);","handlingStrategy":"validation","validationCode":"// Guard before constructing the listener\nif (queueSize < 1 || batchMaxSize < 1) {\n    throw new IllegalArgumentException(\n        \"queueSize and batchMaxSize must be >= 1, got queue=\" + queueSize + \" batch=\" + batchMaxSize);\n}\nreturn new SimplexTransferListener(delegate, queueSize, batchMaxSize, blockOnLastEvent);","typeGuard":null,"tryCatchPattern":"try {\n    return new SimplexTransferListener(delegate, queueSize, batchMaxSize, blockOnLastEvent);\n} catch (IllegalArgumentException e) {\n    if (\"Queue and batch sizes must be greater than 1\".equals(e.getMessage())) {\n        // fall back to documented defaults rather than crashing the transfer UI\n        return new SimplexTransferListener(delegate, 1024, 500, blockOnLastEvent);\n    }\n    throw e;\n}","preventionTips":["Clamp externally supplied sizes: Math.max(1, value) before construction.","Default to the documented 1024/500 unless measurement justifies other values.","Validate numeric config at load time with clear messages instead of letting constructor exceptions surface mid-build."],"tags":["maven","transfer-listener","constructor","invalid-argument","api-misuse"],"backgroundTag":"invalid-constructor-argument","analyzedSha":"e4093d4e120eac99d6bdce5ba67cace2f3085c97","analyzedAt":"2026-08-21T22:58:24.034Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}