{"record":{"id":"06c4c1abb4a4f919","repo":"alibaba/nacos","slug":"pageno-and-pagesize-must-be-greater-than-zero-06c4c1","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/extrnal/ExternalStoragePaginationHelperImpl.java","lineNumber":116,"sourceCode":"        List<E> result = jdbcTemplate.query(sqlFetchRows, args, rowMapper);\n        for (E item : result) {\n            page.getPageItems().add(item);\n        }\n        return page;\n    }\n    \n    @Override\n    public void updateLimit(final String sql, final Object[] args) {\n        try {\n            jdbcTemplate.update(sql, args);\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 = jdbcTemplate.queryForObject(sqlCountRows, countAgrs, Integer.class);\n        } else {\n            rowCountInt = jdbcTemplate.queryForObject(sqlCountRows, Integer.class);\n        }\n        if (null == rowCountInt) {\n            throw new IllegalArgumentException(\"fetchPageLimit error\");\n        }\n        ","sourceCodeStart":98,"sourceCodeEnd":134,"githubUrl":"https://github.com/alibaba/nacos/blob/9b989acdf181d00898f2e8839257bb2b2a3cefe3/persistence/src/main/java/com/alibaba/nacos/persistence/repository/extrnal/ExternalStoragePaginationHelperImpl.java#L98-L134","documentation":"Mirror of the embedded helper: ExternalStoragePaginationHelperImpl.checkPageInfo throws IllegalArgumentException when pageNo or pageSize <= 0. This helper backs pagination when Nacos runs against an external (MySQL/PostgreSQL) database via JdbcTemplate.","triggerScenarios":"Calling a paginated admin/console API backed by external relational storage with pageNo<=0 or pageSize<=0. The same validation as the embedded path but reached only when the server is configured for MySQL/PostgreSQL persistence.","commonSituations":"Identical root causes as the embedded variant: 0-based page indexing, missing pageSize default, or negative values forwarded by a client. Surfaces specifically in deployments using nacos.persistence.type=mysql/postgresql.","solutions":["Send pageNo>=1 and pageSize>=1 (1-based paging).","Check whether the storage type changed (embedded vs external) which routes to a different helper but with identical validation.","Add controller-level validation so bad paging never reaches the persistence layer."],"exampleFix":"// before\nrequest.addParameter(\"pageNo\", \"0\");\nrequest.addParameter(\"pageSize\", \"0\");\n\n// after\nrequest.addParameter(\"pageNo\", String.valueOf(Math.max(1, page)));\nrequest.addParameter(\"pageSize\", String.valueOf(size > 0 ? size : 20));","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":["Same 1-based paging rule applies to the external (MySQL/PostgreSQL) store.","When switching storage types, pagination validation is identical; do not assume different rules.","Forward only validated page parameters from edge to persistence."],"tags":["persistence","external","pagination","illegal-argument"],"backgroundTag":null,"analyzedSha":"9b989acdf181d00898f2e8839257bb2b2a3cefe3","analyzedAt":"2026-08-14T07:17:31.569Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}