{"record":{"id":"d2b5be605d297cd4","repo":"alibaba/nacos","slug":"parameter-validate-error-d2b5be","errorCode":"PARAMETER_VALIDATE_ERROR","errorMessage":"cursor must be >= 0","messagePattern":"cursor must be >= 0","errorType":"validation","errorClass":"NacosApiException","httpStatus":400,"severity":"error","filePath":"ai-registry-adaptor/src/main/java/com/alibaba/nacos/airegistry/form/ListServersOfficialForm.java","lineNumber":94,"sourceCode":"    public void setUpdatedSince(String updatedSince) {\n        this.updatedSince = updatedSince;\n    }\n    \n    /**\n     * 解析 cursor 字段为 offset 数值.\n     * 当 cursor 为空时返回 0；当为非法数字时抛出 NacosApiException.\n     *\n     * @return offset 数值\n     * @throws NacosApiException 当 cursor 非法或为负数\n     */\n    public int resolveOffset() throws NacosApiException {\n        if (cursor == null || cursor.isEmpty()) {\n            return 0;\n        }\n        try {\n            int off = Integer.parseInt(cursor);\n            if (off < 0) {\n                throw new NacosApiException(HttpStatus.BAD_REQUEST.value(),\n                    ErrorCode.PARAMETER_VALIDATE_ERROR, \"cursor must be >= 0\");\n            }\n            return off;\n        } catch (NumberFormatException e) {\n            throw new NacosApiException(HttpStatus.BAD_REQUEST.value(),\n                ErrorCode.PARAMETER_VALIDATE_ERROR, \"cursor must be numeric\");\n        }\n    }\n    \n    @Override\n    public void validate() throws NacosApiException {\n        if (limit == null) {\n            limit = DEFAULT_LIMIT;\n        }\n        if (limit < 0) {\n            throw new NacosApiException(HttpStatus.BAD_REQUEST.value(),\n                ErrorCode.PARAMETER_VALIDATE_ERROR, \"limit must be >= 0\");\n        }","sourceCodeStart":76,"sourceCodeEnd":112,"githubUrl":"https://github.com/alibaba/nacos/blob/9b989acdf181d00898f2e8839257bb2b2a3cefe3/ai-registry-adaptor/src/main/java/com/alibaba/nacos/airegistry/form/ListServersOfficialForm.java#L76-L112","documentation":"ListServersOfficialForm.resolveOffset parses the cursor string as an integer offset. A value that parses but is negative throws PARAMETER_VALIDATE_ERROR (HTTP 400).","triggerScenarios":"Calling the official list-servers endpoint with ?cursor=-1 or any negative numeric cursor.","commonSituations":"Reusing a cursor token that was decremented; computing the next cursor from a negative offset; defaulting an empty cursor to -1.","solutions":["Send a non-negative cursor (start at 0).","Echo back the server-returned pageToken/cursor verbatim rather than recomputing it.","Clamp any computed cursor to 0."],"exampleFix":"// before\nGET /servers?cursor=-10\n\n// after\nGET /servers?cursor=0","handlingStrategy":"validation","validationCode":"int off = cursor == null || cursor.isEmpty() ? 0 : Integer.parseInt(cursor);\nif (off < 0) throw new IllegalArgumentException(\"cursor must be >= 0\");\nuri.queryParam(\"cursor\", off);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Echo the server-returned cursor verbatim.","Start paging from 0 (or omit cursor).","Never decrement the cursor client-side."],"tags":["pagination","validation","cursor","ard","ai"],"backgroundTag":null,"analyzedSha":"9b989acdf181d00898f2e8839257bb2b2a3cefe3","analyzedAt":"2026-08-14T07:17:31.569Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}