{"record":{"id":"ba4d2400a8b07a1a","repo":"binarywang/WxJava","slug":"fieldlist","errorCode":null,"errorMessage":"fieldList 不能为空","messagePattern":"fieldList 不能为空","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"warning","filePath":"weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpHrServiceImpl.java","lineNumber":70,"sourceCode":"    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 不能为空\");\n    }\n    if (fieldList == null || fieldList.isEmpty()) {\n      throw new IllegalArgumentException(\"fieldList 不能为空\");\n    }\n    JsonObject jsonObject = new JsonObject();\n    jsonObject.addProperty(\"userid\", userid);\n    jsonObject.add(\"field_list\", WxCpGsonBuilder.create().toJsonTree(fieldList));\n    this.cpService.post(\n      this.cpService.getWxCpConfigStorage().getApiUrl(UPDATE_EMPLOYEE_FIELD_INFO),\n      jsonObject.toString()\n    );\n  }\n}\n","sourceCodeStart":52,"sourceCodeEnd":81,"githubUrl":"https://github.com/binarywang/WxJava/blob/1c43293a3c2c9d7e91304b6d037fb017f680d0c6/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpHrServiceImpl.java#L52-L81","documentation":"Thrown as IllegalArgumentException (unchecked) in updateEmployeeFieldInfo(userid, fieldList) when the fieldList parameter is null or empty. The update API requires at least one field item to write; calling it with nothing to update is meaningless and rejected before the HTTP call.","triggerScenarios":"Calling cpService.getHrService().updateEmployeeFieldInfo(userid, fieldList) where fieldList is null, an empty list, or a list that was cleared after construction.","commonSituations":"Developer builds the field list from a form or data source where all fields are optional, resulting in an empty list when the user submits nothing. Or the list was populated conditionally and no conditions were met.","solutions":["Check fieldList is non-empty before calling: if (fieldList == null || fieldList.isEmpty()) skip the update.","Ensure at least one FieldItem is always added when constructing the list for the update call.","Short-circuit in batch loops: skip records whose fieldList is empty."],"exampleFix":"// before\nList<WxCpHrEmployeeFieldData.FieldItem> fields = new ArrayList<>();\n// fields may remain empty if nothing to update\nservice.updateEmployeeFieldInfo(userid, fields); // throws\n\n// after\nList<WxCpHrEmployeeFieldData.FieldItem> fields = new ArrayList<>();\n// ... populate fields ...\nif (!fields.isEmpty()) {\n  service.updateEmployeeFieldInfo(userid, fields);\n}","handlingStrategy":"validation","validationCode":"if (fieldList == null || fieldList.isEmpty()) {\n    throw new IllegalArgumentException(\"fieldList must not be empty\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Check fieldList is non-empty before calling updateEmployeeFieldInfo.","Short-circuit batch operations when no fields need updating.","Log a debug message when skipping an empty fieldList to aid troubleshooting."],"tags":["weixin-cp","hr","validation","field-list","precondition"],"backgroundTag":null,"analyzedSha":"1c43293a3c2c9d7e91304b6d037fb017f680d0c6","analyzedAt":"2026-08-14T02:29:11.060Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}