{"record":{"id":"ff8072b8fb99b576","repo":"binarywang/WxJava","slug":"userid","errorCode":null,"errorMessage":"userid 不能为空","messagePattern":"userid 不能为空","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"warning","filePath":"weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpHrServiceImpl.java","lineNumber":49,"sourceCode":"    if (fields != null && !fields.isEmpty()) {\n      jsonObject.add(\"fields\", WxCpGsonBuilder.create().toJsonTree(fields));\n    }\n    String response = this.cpService.post(\n      this.cpService.getWxCpConfigStorage().getApiUrl(GET_FIELD_INFO),\n      jsonObject.toString()\n    );\n    return WxCpHrEmployeeFieldInfoResp.fromJson(response);\n  }\n\n  @Override\n  public WxCpHrEmployeeFieldDataResp getEmployeeFieldInfo(String userid, List<String> fields) throws WxErrorException {\n    return getEmployeeFieldInfo(userid, false, fields);\n  }\n\n  @Override\n  public WxCpHrEmployeeFieldDataResp getEmployeeFieldInfo(String userid, boolean getAll, List<String> fields) throws WxErrorException {\n    if (userid == null || userid.trim().isEmpty()) {\n      throw new IllegalArgumentException(\"userid 不能为空\");\n    }\n    JsonObject jsonObject = new JsonObject();\n    jsonObject.addProperty(\"userid\", userid);\n    jsonObject.addProperty(\"get_all\", getAll);\n    if (fields != null && !fields.isEmpty()) {\n      jsonObject.add(\"fields\", WxCpGsonBuilder.create().toJsonTree(fields));\n    }\n    String response = this.cpService.post(\n      this.cpService.getWxCpConfigStorage().getApiUrl(GET_EMPLOYEE_FIELD_INFO),\n      jsonObject.toString()\n    );\n    return WxCpHrEmployeeFieldDataResp.fromJson(response);\n  }\n\n  @Override\n  public void updateEmployeeFieldInfo(String userid, List<WxCpHrEmployeeFieldData.FieldItem> fieldList) throws WxErrorException {\n    if (userid == null || userid.trim().isEmpty()) {\n      throw new IllegalArgumentException(\"userid 不能为空\");","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/binarywang/WxJava/blob/1c43293a3c2c9d7e91304b6d037fb017f680d0c6/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpHrServiceImpl.java#L31-L67","documentation":"Thrown as IllegalArgumentException (unchecked) in getEmployeeFieldInfo(userid, getAll, fields) when the userid parameter is null, empty, or whitespace-only. This is the HR (人事) employee field data query API; the userid identifies the specific employee whose custom field values to retrieve.","triggerScenarios":"Calling cpService.getHrService().getEmployeeFieldInfo(userid, fields) or the three-argument overload with a null/blank userid. Happens when userid comes from an upstream source that may return null (e.g., unselected form field, database join gap).","commonSituations":"Developer iterates over a list of employees and some entries have null userid due to data quality issues, or they pass a request parameter without validation.","solutions":["Validate userid is non-blank before calling: if (StringUtils.isBlank(userid)) skip or log and continue.","Ensure the upstream data source that provides userid is filtered for nulls/empties.","Wrap in try-catch(IllegalArgumentException) if nulls are expected and should be handled gracefully."],"exampleFix":"// before\nString userid = request.getParameter(\"userid\"); // could be null\nservice.getEmployeeFieldInfo(userid, false, fields); // throws if blank\n\n// after\nString userid = request.getParameter(\"userid\");\nif (StringUtils.isNotBlank(userid)) {\n  service.getEmployeeFieldInfo(userid, false, fields);\n}","handlingStrategy":"validation","validationCode":"if (userid == null || userid.trim().isEmpty()) {\n    throw new IllegalArgumentException(\"userid must not be blank\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate userid with StringUtils.isNotBlank(userid) before calling getEmployeeFieldInfo.","Filter out null/blank userids in batch loops before invoking the API.","Use Optional.ofNullable(userid).filter(StringUtils::isNotBlank) for defensive chaining."],"tags":["weixin-cp","hr","validation","userid","precondition"],"backgroundTag":null,"analyzedSha":"1c43293a3c2c9d7e91304b6d037fb017f680d0c6","analyzedAt":"2026-08-14T02:29:11.060Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}