{"record":{"id":"853de5e6a2a62840","repo":"binarywang/WxJava","slug":"0-20","errorCode":null,"errorMessage":"可填充个数：0 ~ 20。","messagePattern":"可填充个数：0 ~ 20。","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"warning","filePath":"weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpKfServiceImpl.java","lineNumber":109,"sourceCode":"  }\n\n  private void validateParameters(String uri, List<String> userIdList, List<String> departmentIdList) {\n    if ((userIdList == null || userIdList.isEmpty()) && (departmentIdList == null || departmentIdList.isEmpty())) {\n      throw new IllegalArgumentException(\"userid_list和department_id_list至少需要填其中一个\");\n    }\n    if (SERVICER_DEL.equals(uri)) {\n      if (userIdList != null && userIdList.size() > 100) {\n        throw new IllegalArgumentException(\"可填充个数：0 ~ 100。超过100个需分批调用。\");\n      }\n      if (departmentIdList != null && departmentIdList.size() > 100) {\n        throw new IllegalArgumentException(\"可填充个数：0 ~ 100。超过100个需分批调用。\");\n      }\n    } else {\n      if (userIdList != null && userIdList.size() > 100) {\n        throw new IllegalArgumentException(\"可填充个数：0 ~ 100。超过100个需分批调用。\");\n      }\n      if (departmentIdList != null && departmentIdList.size() > 20) {\n        throw new IllegalArgumentException(\"可填充个数：0 ~ 20。\");\n      }\n    }\n  }\n\n  private WxCpKfServicerOpResp servicerOp(String openKfid, List<String> userIdList, List<String> departmentIdList, String uri) throws WxErrorException {\n    String url = cpService.getWxCpConfigStorage().getApiUrl(uri);\n\n    JsonObject json = new JsonObject();\n    json.addProperty(\"open_kfid\", openKfid);\n    if (userIdList != null && !userIdList.isEmpty()) {\n      JsonArray userIdArray = new JsonArray();\n      userIdList.forEach(userIdArray::add);\n      json.add(\"userid_list\", userIdArray);\n    }\n    if (departmentIdList != null && !departmentIdList.isEmpty()) {\n      JsonArray departmentIdArray = new JsonArray();\n      departmentIdList.forEach(departmentIdArray::add);\n      json.add(\"department_id_list\", departmentIdArray);","sourceCodeStart":91,"sourceCodeEnd":127,"githubUrl":"https://github.com/binarywang/WxJava/blob/1c43293a3c2c9d7e91304b6d037fb017f680d0c6/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpKfServiceImpl.java#L91-L127","documentation":"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.","triggerScenarios":"Calling addServicer(openKfid, userIdList, departmentIdList) where departmentIdList.size() > 20. Happens when adding many departments as servicer groups at once.","commonSituations":"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.","solutions":["Split departmentIdList into batches of 20 or fewer for add operations.","Be aware that addServicer has a different department limit (20) than delServicer (100).","Pre-validate: if (departmentIdList != null && departmentIdList.size() > 20) partition into chunks of 20."],"exampleFix":"// before\nList<String> allDepts = orgService.getAllDeptIds(); // 30 entries\nservice.addServicer(openKfid, null, allDepts); // throws > 20\n\n// after\nfor (List<String> batch : partition(allDepts, 20)) {\n  service.addServicer(openKfid, null, batch);\n}","handlingStrategy":"validation","validationCode":"if (departmentIdList != null && departmentIdList.size() > 20) {\n    List<List<String>> batches = partition(departmentIdList, 20);\n    for (List<String> batch : batches) {\n        service.addServicer(openKfid, null, batch);\n    }\n    return;\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Remember that addServicer has a tighter department limit (20) compared to delServicer (100).","Partition departmentIdList into batches of 20 for add operations specifically.","Use different batch sizes for add vs delete to respect each API's distinct limits."],"tags":["weixin-cp","kf","servicer","validation","limit","batch"],"backgroundTag":null,"analyzedSha":"1c43293a3c2c9d7e91304b6d037fb017f680d0c6","analyzedAt":"2026-08-14T02:29:11.060Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}