binarywang/WxJava · warning · IllegalArgumentException

userid_list和department_id_list至少需要填其中一个

Error message

userid_list和department_id_list至少需要填其中一个

What it means

Thrown as IllegalArgumentException (unchecked) in the private validateParameters method of WxCpKfServiceImpl when both userIdList and departmentIdList are null or empty simultaneously. The customer service (客服) servicer add/delete API requires at least one of these two lists to identify which servicers to operate on. This check fires only on the overloaded methods that call validateParameters (the ones with departmentIdList parameter).

Source

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

  public WxCpKfServicerOpResp addServicer(String openKfId, List<String> userIdList, List<String> departmentIdList) throws WxErrorException {
    validateParameters(SERVICER_ADD, userIdList, departmentIdList);
    return servicerOp(openKfId, userIdList, departmentIdList, SERVICER_ADD);
  }

  @Override
  public WxCpKfServicerOpResp delServicer(String openKfid, List<String> userIdList) throws WxErrorException {
    return servicerOp(openKfid, userIdList, null, SERVICER_DEL);
  }

  @Override
  public WxCpKfServicerOpResp delServicer(String openKfid, List<String> userIdList, List<String> departmentIdList) throws WxErrorException {
    validateParameters(SERVICER_DEL, userIdList, departmentIdList);
    return servicerOp(openKfid, userIdList, departmentIdList, SERVICER_DEL);
  }

  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。");
      }
    }
  }

View on GitHub (pinned to 1c43293a3c)

Solutions

  1. Ensure at least one of userIdList or departmentIdList is non-empty before calling addServicer/delServicer.
  2. Validate at the caller: if ((userIdList == null || userIdList.isEmpty()) && (departmentIdList == null || departmentIdList.isEmpty())) skip or prompt the user.
  3. Use the two-argument overloads (userIdList only) if you only ever pass user IDs, to avoid this validation path.

Example fix

// before
List<String> users = getSelectedUsers(); // empty
List<String> depts = getSelectedDepts(); // empty
service.addServicer(openKfid, users, depts); // throws

// after
List<String> users = getSelectedUsers();
List<String> depts = getSelectedDepts();
if ((users != null && !users.isEmpty()) || (depts != null && !depts.isEmpty())) {
  service.addServicer(openKfid, users, depts);
}
Defensive patterns

Strategy: validation

Validate before calling

boolean hasUsers = userIdList != null && !userIdList.isEmpty();
boolean hasDepts = departmentIdList != null && !departmentIdList.isEmpty();
if (!hasUsers && !hasDepts) {
    throw new IllegalArgumentException("At least one of userIdList or departmentIdList is required");
}

Prevention

When it happens

Trigger: Calling addServicer(openKfid, userIdList, departmentIdList) or delServicer(openKfid, userIdList, departmentIdList) with both lists null or both empty. Note: the two-argument overloads (userIdList only) skip validation entirely and call servicerOp directly.

Common situations: Developer passes two empty collections from a form where neither individual users nor departments were selected. Or null propagates from optional parameters that were not provided.

Related errors


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