{"record":{"id":"9337f98499b174a6","repo":"apache/cassandra","slug":"the-page-size-cannot-be-0-9337f9","errorCode":null,"errorMessage":"The page size cannot be 0","messagePattern":"The page size cannot be 0","errorType":"exception","errorClass":"ProtocolException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/transport/messages/QueryMessage.java","lineNumber":109,"sourceCode":"    protected boolean isTraceable()\n    {\n        return true;\n    }\n\n    @Override\n    protected boolean isTrackable()\n    {\n        return true;\n    }\n\n    @Override\n    protected Message.Response execute(QueryState state, Dispatcher.RequestTime requestTime, boolean traceRequest)\n    {\n        CQLStatement statement = null;\n        try\n        {\n            if (options.getPageSize() == 0)\n                throw new ProtocolException(\"The page size cannot be 0\");\n\n            if (traceRequest)\n                traceQuery(state);\n\n            long queryStartTime = currentTimeMillis();\n\n            QueryHandler queryHandler = ClientState.getCQLQueryHandler();\n            statement = queryHandler.parse(query, state, options);\n            Message.Response response = queryHandler.process(statement, state, options, getCustomPayload(), requestTime);\n            QueryEvents.instance.notifyQuerySuccess(statement, query, options, state, queryStartTime, response);\n\n            if (options.skipMetadata() && response instanceof ResultMessage.Rows)\n                ((ResultMessage.Rows)response).result.metadata.setSkipMetadata();\n\n            return response;\n        }\n        catch (Exception e)\n        {","sourceCodeStart":91,"sourceCodeEnd":127,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/transport/messages/QueryMessage.java#L91-L127","documentation":"ProtocolException from QueryMessage.execute when the client supplies a paging state request with page size exactly 0. Page size 0 is undefined in the native protocol (negative means unlimited); zero is rejected before statement execution so the driver receives a protocol error rather than a broken result page.","triggerScenarios":"Sending a QueryMessage (simple, non-prepared query) with query options whose getPageSize() == 0 — e.g. setting fetch size 0 to mean \"no limit\" instead of using a positive number or MAX_VALUE.","commonSituations":"Config values defaulting to 0 wired into the driver's fetch size; hand-rolled protocol clients computing pageSize from user input; language bindings that pass 0 through unchecked.","solutions":["Use a positive page size (e.g. 1000–5000) or Integer.MAX_VALUE for unpaged results","Let the driver auto-page via iterator/executeAsync paging instead of manual paging options","Validate/normalize page size at the config boundary, treating 0 or negative as \"use default\"","Omit page size option when defaults are acceptable"],"exampleFix":"// before\nQueryMessage msg = new QueryMessage(cql, optsWithPageSize(0));\n// after\nQueryMessage msg = new QueryMessage(cql, optsWithPageSize(5000));","handlingStrategy":"validation","validationCode":"if (opts.getPageSize() == 0)\n    throw new IllegalArgumentException(\"page size must be positive; use Integer.MAX_VALUE for no paging\");","typeGuard":null,"tryCatchPattern":"try {\n    session.execute(query);\n} catch (ProtocolException e) {\n    if (e.getMessage().contains(\"page size cannot be 0\"))\n        session.execute(query.setFetchSize(5000));\n    else throw e;\n}","preventionTips":["Never pass user-controlled page size straight into fetch size","Treat 0/negative page size as \"use default\" during config load","Rely on driver paging iterators instead of manual sizing","Log and normalize invalid page-size values at startup"],"tags":["cql","paging","protocol","invalid-request"],"backgroundTag":"value-out-of-range","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}