{"record":{"id":"2ba2e72081d82075","repo":"alibaba/nacos","slug":"pageno-and-pagesize-must-be-greater-than-zero","errorCode":null,"errorMessage":"pageNo and pageSize must be greater than zero","messagePattern":"pageNo and pageSize must be greater than zero","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"persistence/src/main/java/com/alibaba/nacos/persistence/repository/embedded/EmbeddedPaginationHelperImpl.java","lineNumber":118,"sourceCode":"        return fetchPageLimit(countMapperResult.getSql(),\n            countMapperResult.getParamList().toArray(),\n            mapperResult.getSql(), mapperResult.getParamList().toArray(), pageNo, pageSize,\n            rowMapper);\n    }\n    \n    @Override\n    public void updateLimit(final String sql, final Object[] args) {\n        EmbeddedStorageContextHolder.addSqlContext(sql, args);\n        try {\n            databaseOperate.update(EmbeddedStorageContextHolder.getCurrentSqlContext());\n        } finally {\n            EmbeddedStorageContextHolder.cleanAllContext();\n        }\n    }\n    \n    private void checkPageInfo(final int pageNo, final int pageSize) {\n        if (pageNo <= 0 || pageSize <= 0) {\n            throw new IllegalArgumentException(\"pageNo and pageSize must be greater than zero\");\n        }\n    }\n    \n    private Page<E> doFetchPage(final String sqlCountRows, final Object[] countAgrs,\n        final String sqlFetchRows,\n        final Object[] fetchArgs, final int pageNo, final int pageSize, final RowMapper rowMapper) {\n        checkPageInfo(pageNo, pageSize);\n        // Query the total number of current records\n        Integer rowCountInt = null;\n        if (null != countAgrs) {\n            rowCountInt = databaseOperate.queryOne(sqlCountRows, countAgrs, Integer.class);\n        } else {\n            rowCountInt = databaseOperate.queryOne(sqlCountRows, Integer.class);\n        }\n        if (rowCountInt == null) {\n            throw new IllegalArgumentException(\"fetchPageLimit error\");\n        }\n        ","sourceCodeStart":100,"sourceCodeEnd":136,"githubUrl":"https://github.com/alibaba/nacos/blob/9b989acdf181d00898f2e8839257bb2b2a3cefe3/persistence/src/main/java/com/alibaba/nacos/persistence/repository/embedded/EmbeddedPaginationHelperImpl.java#L100-L136","documentation":"Thrown by EmbeddedPaginationHelperImpl.checkPageInfo (private) when pageNo or pageSize is <= 0, as an IllegalArgumentException before any query runs. This helper backs pagination for the embedded Derby storage.","triggerScenarios":"Calling a paginated admin/console API (config history, namespace list, etc.) backed by embedded storage with pageNo=0, pageNo<0, pageSize=0, or pageSize<0. Also triggered by internal services that forward zero/negative page parameters from a request.","commonSituations":"Clients using 0-based page indexing while Nacos expects 1-based; defaulting pageSize to 0 when the request omits it; off-by-one bugs in pagination parameter forwarding.","solutions":["Ensure pageNo and pageSize are both >= 1 in the request (Nacos uses 1-based page numbers).","If the error comes from an internal caller, trace which API forwarded the zero/negative value and fix the default there.","Validate pagination inputs at the controller boundary before delegating to the persistence helper."],"exampleFix":"// before\nint pageNo = 0;     // wrong: 0-based\nint pageSize = 0;\n\n// after\nint pageNo = Math.max(1, requestedPage);\nint pageSize = requestedSize > 0 ? requestedSize : defaultPageSize;","handlingStrategy":"validation","validationCode":"if (pageNo < 1 || pageSize < 1) {\n    throw new IllegalArgumentException(\"pageNo and pageSize must be >= 1\");\n}","typeGuard":"static boolean validPaging(int pageNo, int pageSize) {\n    return pageNo >= 1 && pageSize >= 1;\n}","tryCatchPattern":null,"preventionTips":["Nacos uses 1-based page numbers; never send pageNo=0.","Default pageSize to a positive constant (e.g. 20) when the client omits it.","Validate at the controller boundary so the persistence layer never sees bad values."],"tags":["persistence","embedded","pagination","illegal-argument"],"backgroundTag":null,"analyzedSha":"9b989acdf181d00898f2e8839257bb2b2a3cefe3","analyzedAt":"2026-08-14T07:17:31.569Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}