binarywang/WxJava · warning · IllegalArgumentException
size参数错误,请使用[1-100]填充,默认100
Error message
size参数错误,请使用[1-100]填充,默认100
What it means
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].
Source
Thrown at weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpOaServiceImpl.java:131
new TypeToken<List<WxCpCropCheckinOption>>() {
}.getType()
);
}
@Override
public WxCpApprovalInfo getApprovalInfo(@NonNull Date startTime, @NonNull Date endTime,
Integer cursor, Integer size, List<WxCpApprovalInfoQueryFilter> filters)
throws WxErrorException {
if (cursor == null) {
cursor = 0;
}
if (size == null) {
size = 100;
}
if (size < 0 || size > 100) {
throw new IllegalArgumentException("size参数错误,请使用[1-100]填充,默认100");
}
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("starttime", startTime.getTime() / 1000L);
jsonObject.addProperty("endtime", endTime.getTime() / 1000L);
jsonObject.addProperty("size", size);
jsonObject.addProperty("cursor", cursor);
if (filters != null && !filters.isEmpty()) {
JsonArray filterJsonArray = new JsonArray();
for (WxCpApprovalInfoQueryFilter filter : filters) {
filterJsonArray.add(JsonParser.parseString(filter.toJson()));
}
jsonObject.add("filters", filterJsonArray);
}
final String url = this.mainService.getWxCpConfigStorage().getApiUrl(GET_APPROVAL_INFO);
String responseContent = this.mainService.post(url, jsonObject.toString());View on GitHub (pinned to 1c43293a3c)
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
Example fix
// before WxCpApprovalInfo info = oaService.getApprovalInfo(start, end, cursor, userPageSize, filters); // userPageSize = 200 // after — clamp to valid range int safeSize = (userPageSize == null) ? 100 : Math.max(1, Math.min(userPageSize, 100)); WxCpApprovalInfo info = oaService.getApprovalInfo(start, end, cursor, safeSize, filters);
Defensive patterns
Strategy: validation
Validate before calling
// Clamp size to valid range before calling Integer safeSize = (size == null) ? null : Math.max(1, Math.min(size, 100)); // Or pass null to accept the SDK default of 100
Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- 用户列表不能为空,不超过 100 个,若用户超过 100 个,请分批获取
- 获取记录时间跨度不超过一个月
- 受限于网络传输,起止时间的最大跨度为30天,如超过30天,则以结束时间为基准向前取30天进行查询
- 微信开放平台 appId 不能为空
- 微信开放平台 secret 不能为空
AI-assisted analysis of binarywang/WxJava@1c43293a3c (2026-08-14).
Data as JSON: /api/errors/0d2b66620f716ca5.
Report an issue: GitHub.