{"record":{"id":"2c1a132e339baa55","repo":"pagehelper-org/Mybatis-PageHelper","slug":"pagination-parameters-are-not-a-valid-number-type","errorCode":null,"errorMessage":"pagination parameters are not a valid number type!","messagePattern":"pagination parameters are not a valid number type!","errorType":"exception","errorClass":"PageException","httpStatus":null,"severity":"error","filePath":"src/main/java/com/github/pagehelper/util/PageObjectUtil.java","lineNumber":126,"sourceCode":"        if (orderBy != null && orderBy.toString().length() > 0) {\n            hasOrderBy = true;\n        }\n        try {\n            Object _pageNum = getParamValue(paramsObject, \"pageNum\", required);\n            Object _pageSize = getParamValue(paramsObject, \"pageSize\", required);\n            if (_pageNum == null || _pageSize == null) {\n                if(hasOrderBy){\n                    Page page = new Page();\n                    page.setOrderBy(orderBy.toString());\n                    page.setOrderByOnly(true);\n                    return page;\n                }\n                return null;\n            }\n            pageNum = Integer.parseInt(String.valueOf(_pageNum));\n            pageSize = Integer.parseInt(String.valueOf(_pageSize));\n        } catch (NumberFormatException e) {\n            throw new PageException(\"pagination parameters are not a valid number type!\", e);\n        }\n        Page page = new Page(pageNum, pageSize);\n        //count查询\n        Object _count = getParamValue(paramsObject, \"count\", false);\n        if (_count != null) {\n            page.setCount(Boolean.valueOf(String.valueOf(_count)));\n        }\n        //排序\n        if (hasOrderBy) {\n            page.setOrderBy(orderBy.toString());\n        }\n        //分页合理化\n        Object reasonable = getParamValue(paramsObject, \"reasonable\", false);\n        if (reasonable != null) {\n            page.setReasonable(Boolean.valueOf(String.valueOf(reasonable)));\n        }\n        //查询全部\n        Object pageSizeZero = getParamValue(paramsObject, \"pageSizeZero\", false);","sourceCodeStart":108,"sourceCodeEnd":144,"githubUrl":"https://github.com/pagehelper-org/Mybatis-PageHelper/blob/c692616c5bc95b41aa779b502f991825c8e5acbc/src/main/java/com/github/pagehelper/util/PageObjectUtil.java#L108-L144","documentation":"PageHelper read the pageNum/pageSize values from the parameter object but could not parse them into integers — Integer.parseInt failed with NumberFormatException, which is wrapped in a PageException. The paging parameters exist but are not valid number types (e.g. \"abc\", \"12.5\", or a non-numeric object).","triggerScenarios":"Passing pageNum=\"abc\" or pageSize=\"3.5\" in a Map used for paging; passing a non-numeric Object (e.g. a Locale or array) under the _pageNum/_pageSize keys; HTTP query params bound as raw strings with typos or empty strings placed into the paging map.","commonSituations":"Spring binds request parameters as Strings and a user supplies page=two; frontend sends pageSize=10.0 from JS floats; a config file supplies non-numeric defaults; a JSON deserializer yields Doubles with decimal points that fail parseInt.","solutions":["Validate/sanitize pageNum and pageSize before calling the paging API (parse with NumberUtils and fall back to defaults)","Ensure values are whole numbers: trim strings, reject/round decimals, and empty-check before paging","If values come from HTTP, bind them as Integer in the DTO so the framework fails fast with a clean 400","Wrap the paging call in try-catch for PageException and degrade to default paging instead of failing the request"],"exampleFix":"// before\nparams.put(\"pageNum\", request.getParameter(\"page\")); // may be \"abc\"\nPageHelper.startPage(params);\n// after\nint pageNum = NumberUtils.toInt(request.getParameter(\"page\"), 1);\nint pageSize = NumberUtils.toInt(request.getParameter(\"size\"), 10);\nPageHelper.startPage(pageNum, pageSize);","handlingStrategy":"validation","validationCode":"Object pn = map.get(\"pageNum\"), ps = map.get(\"pageSize\");\nif (pn == null || ps == null\n    || !pn.toString().matches(\"\\\\d+\")\n    || !ps.toString().matches(\"\\\\d+\")) {\n    throw new IllegalArgumentException(\"pageNum/pageSize must be positive integers\");\n}\nPageHelper.startPage(map);","typeGuard":null,"tryCatchPattern":"try {\n    PageHelper.startPage(params);\n} catch (PageException e) {\n    log.warn(\"invalid paging numbers, using defaults: {}\", e.getMessage());\n    PageHelper.startPage(1, 10);\n}","preventionTips":["Bind HTTP paging params as Integer fields in DTOs, not String","Reject decimals/empty strings at the API boundary with 400 responses","Use NumberUtils.toInt(value, default) for tolerant parsing before paging"],"tags":["pagination","number-format","validation","mybatis","pagehelper"],"backgroundTag":"invalid-argument-format","analyzedSha":"c692616c5bc95b41aa779b502f991825c8e5acbc","analyzedAt":"2026-09-08T03:50:49.192Z","contentChangedAt":"2026-09-08T03:50:49.192Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}