{"record":{"id":"0d2b66620f716ca5","repo":"binarywang/WxJava","slug":"size-1-100-100","errorCode":null,"errorMessage":"size参数错误,请使用[1-100]填充，默认100","messagePattern":"size参数错误,请使用\\[1-100\\]填充，默认100","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"warning","filePath":"weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpOaServiceImpl.java","lineNumber":131,"sourceCode":"      new TypeToken<List<WxCpCropCheckinOption>>() {\n      }.getType()\n    );\n  }\n\n  @Override\n  public WxCpApprovalInfo getApprovalInfo(@NonNull Date startTime, @NonNull Date endTime,\n                                          Integer cursor, Integer size, List<WxCpApprovalInfoQueryFilter> filters)\n    throws WxErrorException {\n    if (cursor == null) {\n      cursor = 0;\n    }\n\n    if (size == null) {\n      size = 100;\n    }\n\n    if (size < 0 || size > 100) {\n      throw new IllegalArgumentException(\"size参数错误,请使用[1-100]填充，默认100\");\n    }\n\n    JsonObject jsonObject = new JsonObject();\n    jsonObject.addProperty(\"starttime\", startTime.getTime() / 1000L);\n    jsonObject.addProperty(\"endtime\", endTime.getTime() / 1000L);\n    jsonObject.addProperty(\"size\", size);\n    jsonObject.addProperty(\"cursor\", cursor);\n\n    if (filters != null && !filters.isEmpty()) {\n      JsonArray filterJsonArray = new JsonArray();\n      for (WxCpApprovalInfoQueryFilter filter : filters) {\n        filterJsonArray.add(JsonParser.parseString(filter.toJson()));\n      }\n      jsonObject.add(\"filters\", filterJsonArray);\n    }\n\n    final String url = this.mainService.getWxCpConfigStorage().getApiUrl(GET_APPROVAL_INFO);\n    String responseContent = this.mainService.post(url, jsonObject.toString());","sourceCodeStart":113,"sourceCodeEnd":149,"githubUrl":"https://github.com/binarywang/WxJava/blob/1c43293a3c2c9d7e91304b6d037fb017f680d0c6/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpOaServiceImpl.java#L113-L149","documentation":"Thrown (as unchecked IllegalArgumentException) by the cursor-based getApprovalInfo() overload when the size parameter (after null-defaulting to 100) is less than 0 or greater than 100. WeChat's approval-info API restricts page size to the range [1, 100].","triggerScenarios":"Passing a negative size value or a value above 100 to getApprovalInfo(startTime, endTime, cursor, size, filters). The check is `size < 0 || size > 100`. Note: size=0 passes this check but is likely meaningless.","commonSituations":"Passing a size from user input without clamping; using a default pagination size from another system that exceeds 100; accidentally passing -1 as a sentinel.","solutions":["Clamp size to the [1, 100] range before calling: size = Math.max(1, Math.min(size, 100))","Pass null to accept the default of 100 when you want the maximum page","Validate size at the caller layer before invoking the API"],"exampleFix":"// before\nWxCpApprovalInfo info = oaService.getApprovalInfo(start, end, cursor, userPageSize, filters); // userPageSize = 200\n\n// after — clamp to valid range\nint safeSize = (userPageSize == null) ? 100 : Math.max(1, Math.min(userPageSize, 100));\nWxCpApprovalInfo info = oaService.getApprovalInfo(start, end, cursor, safeSize, filters);","handlingStrategy":"validation","validationCode":"// Clamp size to valid range before calling\nInteger safeSize = (size == null) ? null : Math.max(1, Math.min(size, 100));\n// Or pass null to accept the SDK default of 100","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Clamp pagination size at the caller layer: Math.max(1, Math.min(size, 100))","Pass null for size to use the default maximum of 100 when you want the largest page","Note that size=0 passes the current check but is likely invalid — treat 0 as null"],"tags":["wechat-cp","oa","approval","validation","parameter-limit","pagination"],"backgroundTag":null,"analyzedSha":"1c43293a3c2c9d7e91304b6d037fb017f680d0c6","analyzedAt":"2026-08-14T02:29:11.060Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}