{"record":{"id":"56dbd2fbcac44572","repo":"alibaba/nacos","slug":"parameter-validate-error-56dbd2","errorCode":"PARAMETER_VALIDATE_ERROR","errorMessage":"Parameter 'offset' must >= 0","messagePattern":"Parameter 'offset' must >= 0","errorType":"validation","errorClass":"NacosApiException","httpStatus":400,"severity":"error","filePath":"ai-registry-adaptor/src/main/java/com/alibaba/nacos/airegistry/form/ListServerForm.java","lineNumber":90,"sourceCode":"    }\n    \n    public String getSearchMode() {\n        return searchMode;\n    }\n    \n    public void setSearchMode(String searchMode) {\n        this.searchMode = searchMode;\n    }\n    \n    /**\n     * check form parameters while valid.\n     *\n     * @throws NacosApiException when form parameters is invalid.\n     */\n    @Override\n    public void validate() throws NacosApiException {\n        if (offset < 0) {\n            throw new NacosApiException(HttpStatus.BAD_REQUEST.value(),\n                ErrorCode.PARAMETER_VALIDATE_ERROR,\n                \"Parameter 'offset' must >= 0\");\n        }\n        \n        if (limit > Constants.MAX_LIST_SIZE) {\n            throw new NacosApiException(HttpStatus.BAD_REQUEST.value(),\n                ErrorCode.PARAMETER_VALIDATE_ERROR,\n                \"Parameter 'limit' must <= 100\");\n        }\n        \n        if (StringUtils.isNotEmpty(searchMode)) {\n            if (!Constants.MCP_LIST_SEARCH_BLUR.equals(searchMode)\n                && !Constants.MCP_LIST_SEARCH_ACCURATE.equals(searchMode)) {\n                throw new NacosApiException(HttpStatus.BAD_REQUEST.value(),\n                    ErrorCode.PARAMETER_MISMATCH,\n                    \"Parameter 'searchMode' must be \" + Constants.MCP_LIST_SEARCH_BLUR + \" or \"\n                        + Constants.MCP_LIST_SEARCH_ACCURATE);\n            }","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/alibaba/nacos/blob/9b989acdf181d00898f2e8839257bb2b2a3cefe3/ai-registry-adaptor/src/main/java/com/alibaba/nacos/airegistry/form/ListServerForm.java#L72-L108","documentation":"ListServerForm validates pagination for the ARD list-servers endpoint. offset must be non-negative; a negative offset throws PARAMETER_VALIDATE_ERROR (HTTP 400).","triggerScenarios":"Calling the list-servers endpoint with ?offset set to a negative number (e.g. -1).","commonSituations":"Computing offset as (page-1)*pageSize when page is 0 or negative; arithmetic underflow; defaulting an unset page to -1.","solutions":["Send offset >= 0 (the first page is offset 0).","Clamp the computed offset to 0 before the call.","Check that your page index is 1-based (or 0-based) consistently with the formula."],"exampleFix":"// before\nint offset = (page - 1) * size; // page can be 0 -> offset = -size\n\n// after\nint page = Math.max(page, 1);\nint offset = (page - 1) * size;","handlingStrategy":"validation","validationCode":"int page = Math.max(pageArg, 1);\nint offset = (page - 1) * pageSize;\nif (offset < 0) throw new IllegalArgumentException(\"offset must be >= 0\");\nuri.queryParam(\"offset\", offset);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat the first page as offset 0.","Clamp computed offsets to 0.","Unit-test pagination math at page=0 and page=1."],"tags":["pagination","validation","ard","ai"],"backgroundTag":null,"analyzedSha":"9b989acdf181d00898f2e8839257bb2b2a3cefe3","analyzedAt":"2026-08-14T07:17:31.569Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}