binarywang/WxJava · warning · IllegalArgumentException

可填充个数:0 ~ 20。

Error message

可填充个数:0 ~ 20。

What it means

Thrown as IllegalArgumentException (unchecked) in validateParameters when the operation is SERVICER_ADD and departmentIdList contains more than 20 entries. Unlike userid_list (100), the add-servicer API has a stricter cap of 20 for department_id_list. This guard fires in the else branch (add path) before the HTTP request.

Source

Thrown at weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpKfServiceImpl.java:109

  }

  private void validateParameters(String uri, List<String> userIdList, List<String> departmentIdList) {
    if ((userIdList == null || userIdList.isEmpty()) && (departmentIdList == null || departmentIdList.isEmpty())) {
      throw new IllegalArgumentException("userid_list和department_id_list至少需要填其中一个");
    }
    if (SERVICER_DEL.equals(uri)) {
      if (userIdList != null && userIdList.size() > 100) {
        throw new IllegalArgumentException("可填充个数:0 ~ 100。超过100个需分批调用。");
      }
      if (departmentIdList != null && departmentIdList.size() > 100) {
        throw new IllegalArgumentException("可填充个数:0 ~ 100。超过100个需分批调用。");
      }
    } else {
      if (userIdList != null && userIdList.size() > 100) {
        throw new IllegalArgumentException("可填充个数:0 ~ 100。超过100个需分批调用。");
      }
      if (departmentIdList != null && departmentIdList.size() > 20) {
        throw new IllegalArgumentException("可填充个数:0 ~ 20。");
      }
    }
  }

  private WxCpKfServicerOpResp servicerOp(String openKfid, List<String> userIdList, List<String> departmentIdList, String uri) throws WxErrorException {
    String url = cpService.getWxCpConfigStorage().getApiUrl(uri);

    JsonObject json = new JsonObject();
    json.addProperty("open_kfid", openKfid);
    if (userIdList != null && !userIdList.isEmpty()) {
      JsonArray userIdArray = new JsonArray();
      userIdList.forEach(userIdArray::add);
      json.add("userid_list", userIdArray);
    }
    if (departmentIdList != null && !departmentIdList.isEmpty()) {
      JsonArray departmentIdArray = new JsonArray();
      departmentIdList.forEach(departmentIdArray::add);
      json.add("department_id_list", departmentIdArray);

View on GitHub (pinned to 1c43293a3c)

Solutions

  1. Split departmentIdList into batches of 20 or fewer for add operations.
  2. Be aware that addServicer has a different department limit (20) than delServicer (100).
  3. Pre-validate: if (departmentIdList != null && departmentIdList.size() > 20) partition into chunks of 20.

Example fix

// before
List<String> allDepts = orgService.getAllDeptIds(); // 30 entries
service.addServicer(openKfid, null, allDepts); // throws > 20

// after
for (List<String> batch : partition(allDepts, 20)) {
  service.addServicer(openKfid, null, batch);
}
Defensive patterns

Strategy: validation

Validate before calling

if (departmentIdList != null && departmentIdList.size() > 20) {
    List<List<String>> batches = partition(departmentIdList, 20);
    for (List<String> batch : batches) {
        service.addServicer(openKfid, null, batch);
    }
    return;
}

Prevention

When it happens

Trigger: Calling addServicer(openKfid, userIdList, departmentIdList) where departmentIdList.size() > 20. Happens when adding many departments as servicer groups at once.

Common situations: Developer reuses the same batching threshold (100) for both userIdList and departmentIdList without realizing the department limit is tighter at 20. Common confusion since DEL allows 100 departments but ADD only allows 20.

Related errors


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