{"record":{"id":"a80d11877c6c7b75","repo":"apache/cassandra","slug":"the-page-size-cannot-be-0","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/ExecuteMessage.java","lineNumber":156,"sourceCode":"            prepared = handler.getPrepared(statementId);\n            if (prepared == null)\n                throw new PreparedQueryNotFoundException(statementId);\n\n            if (!prepared.fullyQualified && prepared.statement.eligibleAsPreparedStatement() && !Objects.equals(state.getClientState().getRawKeyspace(), prepared.keyspace))\n            {\n                state.getClientState().warnAboutUseWithPreparedStatements(statementId, prepared.keyspace);\n\n                String msg = String.format(\"Tried to execute a prepared unqualified statement on a keyspace it was not prepared on. \" +\n                                           \" Executing the resulting prepared statement will return unexpected results: %s (on keyspace %s, previously prepared on %s)\",\n                                           statementId, state.getClientState().getRawKeyspace(), prepared.keyspace);\n                nospam.error(msg);\n            }\n\n            CQLStatement statement = prepared.statement;\n            options.prepare(statement.getBindVariables());\n\n            if (options.getPageSize() == 0)\n                throw new ProtocolException(\"The page size cannot be 0\");\n\n            if (traceRequest)\n                traceQuery(state, prepared);\n\n            if (options.isEligibleForArtificialLatency())\n                ArtificialLatency.setEligibleForArtificialLatency(true);\n\n            // Some custom QueryHandlers are interested by the bound names. We provide them this information\n            // by wrapping the QueryOptions.\n            QueryOptions queryOptions = QueryOptions.addColumnSpecifications(options, prepared.statement.getBindVariables());\n\n            long requestStartTime = currentTimeMillis();\n\n            Message.Response response = handler.processPrepared(statement, state, queryOptions, getCustomPayload(), requestTime);\n\n            QueryEvents.instance.notifyExecuteSuccess(prepared.statement, prepared.rawCQLStatement, options, state, requestStartTime, response);\n\n            if (response instanceof ResultMessage.Rows)","sourceCodeStart":138,"sourceCodeEnd":174,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/transport/messages/ExecuteMessage.java#L138-L174","documentation":"The CQL binary protocol requires a positive page size when paging is requested. ExecuteMessage rejects a page size of exactly 0 with a ProtocolException before running the statement, since 0 would mean an infinite/invalid page.","triggerScenarios":"Sending ExecuteMessage whose query options carry pageSize == 0 — typically a client setting fetch size to 0 intending \"unlimited\" instead of omitting paging or using a positive value / Integer.MAX_VALUE.","commonSituations":"Application code that maps a UI/config \"page size\" input straight into the driver fetch size; misinterpreting protocol docs; rounding/config parsing producing 0.","solutions":["Set the fetch size to a positive value (e.g. 5000) instead of 0","To fetch everything, use the maximum fetch size (Integer.MAX_VALUE) or use the driver's \"no paging\"/auto-paging iteration API","Validate user- or config-supplied page sizes and reject/normalize 0 before sending","Omit the paging options entirely if you don't intend to page"],"exampleFix":"// before\nstatement.setFetchSize(0); // illegal\n// after\nstatement.setFetchSize(5000); // or Integer.MAX_VALUE for all rows","handlingStrategy":"validation","validationCode":"int pageSize = config.pageSize();\nif (pageSize <= 0)\n    pageSize = 5000; // normalize to default\nstatement.setFetchSize(pageSize);","typeGuard":"int safePageSize(Integer n) {\n    return (n == null || n <= 0) ? 5000 : n;\n}","tryCatchPattern":"try {\n    session.execute(statement);\n} catch (ProtocolException e) {\n    if (e.getMessage().contains(\"page size cannot be 0\"))\n        session.execute(statement.setFetchSize(5000));\n    else throw e;\n}","preventionTips":["Validate page size inputs at the config/UI boundary","Map \"unlimited\" to Integer.MAX_VALUE, never 0","Prefer driver auto-paging over manual page-size control","Add a unit test for fetch-size configuration parsing"],"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"}