{"record":{"id":"4e79d28508cbddf2","repo":"binarywang/WxJava","slug":"userid-list-department-id-list","errorCode":null,"errorMessage":"userid_list和department_id_list至少需要填其中一个","messagePattern":"userid_list和department_id_list至少需要填其中一个","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"warning","filePath":"weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpKfServiceImpl.java","lineNumber":95,"sourceCode":"  public WxCpKfServicerOpResp addServicer(String openKfId, List<String> userIdList, List<String> departmentIdList) throws WxErrorException {\n    validateParameters(SERVICER_ADD, userIdList, departmentIdList);\n    return servicerOp(openKfId, userIdList, departmentIdList, SERVICER_ADD);\n  }\n\n  @Override\n  public WxCpKfServicerOpResp delServicer(String openKfid, List<String> userIdList) throws WxErrorException {\n    return servicerOp(openKfid, userIdList, null, SERVICER_DEL);\n  }\n\n  @Override\n  public WxCpKfServicerOpResp delServicer(String openKfid, List<String> userIdList, List<String> departmentIdList) throws WxErrorException {\n    validateParameters(SERVICER_DEL, userIdList, departmentIdList);\n    return servicerOp(openKfid, userIdList, departmentIdList, SERVICER_DEL);\n  }\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","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/binarywang/WxJava/blob/1c43293a3c2c9d7e91304b6d037fb017f680d0c6/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpKfServiceImpl.java#L77-L113","documentation":"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).","triggerScenarios":"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.","commonSituations":"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.","solutions":["Ensure at least one of userIdList or departmentIdList is non-empty before calling addServicer/delServicer.","Validate at the caller: if ((userIdList == null || userIdList.isEmpty()) && (departmentIdList == null || departmentIdList.isEmpty())) skip or prompt the user.","Use the two-argument overloads (userIdList only) if you only ever pass user IDs, to avoid this validation path."],"exampleFix":"// before\nList<String> users = getSelectedUsers(); // empty\nList<String> depts = getSelectedDepts(); // empty\nservice.addServicer(openKfid, users, depts); // throws\n\n// after\nList<String> users = getSelectedUsers();\nList<String> depts = getSelectedDepts();\nif ((users != null && !users.isEmpty()) || (depts != null && !depts.isEmpty())) {\n  service.addServicer(openKfid, users, depts);\n}","handlingStrategy":"validation","validationCode":"boolean hasUsers = userIdList != null && !userIdList.isEmpty();\nboolean hasDepts = departmentIdList != null && !departmentIdList.isEmpty();\nif (!hasUsers && !hasDepts) {\n    throw new IllegalArgumentException(\"At least one of userIdList or departmentIdList is required\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate that at least one list is non-empty before calling addServicer/delServicer with the three-argument overload.","Consider using the two-argument overload if you only ever pass user IDs.","Add form-level validation in the UI to require at least one user or department selection."],"tags":["weixin-cp","kf","servicer","validation","precondition"],"backgroundTag":null,"analyzedSha":"1c43293a3c2c9d7e91304b6d037fb017f680d0c6","analyzedAt":"2026-08-14T02:29:11.060Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}