{"record":{"id":"0e787b28b507ca6f","repo":"quarkusio/quarkus","slug":"demand-must-be-greater-than-zero","errorCode":null,"errorMessage":"Demand must be greater than zero","messagePattern":"Demand must be greater than zero","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/RestMulti.java","lineNumber":135,"sourceCode":"            }\n\n            /**\n             * Configure the {@code demand} signaled to the wrapped {@link Multi}, defaults to {@code 1}.\n             *\n             * <p>\n             * A demand of {@code 1} guarantees serial/sequential processing, any higher demand supports\n             * concurrent processing. A demand greater {@code 1}, with concurrent {@link Multi} processing,\n             * does not guarantee element order - this means that elements emitted by the\n             * {@link RestMulti#fromMultiData(Multi) RestMulti.fromMultiData(Multi)} source <code>Multi</code>}\n             * will be produced in a non-deterministic order.\n             *\n             * @see MultiMerge#withConcurrency(int) Multi.createBy().merging().withConcurrency(int)\n             * @see Multi#capDemandsTo(long)\n             * @see Multi#capDemandsUsing(LongFunction)\n             */\n            public Builder<T> withDemand(long demand) {\n                if (demand <= 0) {\n                    throw new IllegalArgumentException(\"Demand must be greater than zero\");\n                }\n                this.demand = demand;\n                return this;\n            }\n\n            /**\n             * Configure whether objects produced by the wrapped {@link Multi} are encoded as JSON array elements, which is the\n             * default.\n             *\n             * <p>\n             * {@code encodeAsJsonArray(false)} produces separate JSON objects.\n             *\n             * <p>\n             * This property is only used for JSON object results and ignored for SSE and chunked streaming.\n             */\n            public Builder<T> encodeAsJsonArray(boolean encodeAsJsonArray) {\n                this.encodeAsJsonArray = encodeAsJsonArray;\n                return this;","sourceCodeStart":117,"sourceCodeEnd":153,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/RestMulti.java#L117-L153","documentation":"RestMulti's Builder.withDemand(long) sets the request demand (backpressure batch size) forwarded to the underlying reactive stream. It throws IllegalArgumentException when demand <= 0, because reactive-streams demand must be a positive number.","triggerScenarios":"Calling `RestMulti.fromMulti(aMulti).withDemand(n).build()` with n = 0, a negative value, or a value computed from config/headers that failed to parse to a positive number (e.g. Long.parseLong of an empty string would throw earlier, but a computed 0 reaches this check).","commonSituations":"Configuring demand via a property that defaults to 0 ('unset' sentinel); computing batch size from a page size or chunk config that evaluates to zero; unit tests passing 0 to check behavior.","solutions":["Pass a positive demand, e.g. `withDemand(256)`, or use the builder default by omitting the call.","Validate/clamp configuration values before use: `long demand = Math.max(1, configuredDemand);`","If demand comes from request parameters, validate > 0 and return 400 on invalid input."],"exampleFix":"// before\nlong demand = config.batchSize(); // may be 0 when unset\nreturn RestMulti.fromMulti(multi).withDemand(demand).build();\n// after\nlong demand = config.batchSize() > 0 ? config.batchSize() : 256;\nreturn RestMulti.fromMulti(multi).withDemand(demand).build();","handlingStrategy":"validation","validationCode":"long demand = configuredDemand;\nif (demand <= 0) {\n    demand = DEFAULT_DEMAND; // e.g. 256\n}","typeGuard":"boolean isPositiveDemand(Long d) {\n    return d != null && d > 0;\n}","tryCatchPattern":"try {\n    return RestMulti.fromMulti(multi).withDemand(demand).build();\n} catch (IllegalArgumentException e) {\n    return RestMulti.fromMulti(multi).build(); // fall back to default demand\n}","preventionTips":["Give demand-related config properties sane positive defaults instead of 0-as-unset.","Document that withDemand is backpressure request size and must be > 0.","Clamp all externally supplied batch/demand values with Math.max(1, value)."],"tags":["backpressure","illegal-argument","reactive-streams","resteasy-reactive"],"backgroundTag":"invalid-backpressure-demand","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}