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

  1. Clamp size to the [1, 100] range before calling: size = Math.max(1, Math.min(size, 100))
  2. Pass null to accept the default of 100 when you want the maximum page
  3. 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

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


AI-assisted analysis of binarywang/WxJava@1c43293a3c (2026-08-14). Data as JSON: /api/errors/0d2b66620f716ca5. Report an issue: GitHub.