binarywang/WxJava · warning · IllegalArgumentException
fieldList 不能为空
Error message
fieldList 不能为空
What it means
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.
Source
Thrown at weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpHrServiceImpl.java:70
jsonObject.addProperty("userid", userid);
jsonObject.addProperty("get_all", getAll);
if (fields != null && !fields.isEmpty()) {
jsonObject.add("fields", WxCpGsonBuilder.create().toJsonTree(fields));
}
String response = this.cpService.post(
this.cpService.getWxCpConfigStorage().getApiUrl(GET_EMPLOYEE_FIELD_INFO),
jsonObject.toString()
);
return WxCpHrEmployeeFieldDataResp.fromJson(response);
}
@Override
public void updateEmployeeFieldInfo(String userid, List<WxCpHrEmployeeFieldData.FieldItem> fieldList) throws WxErrorException {
if (userid == null || userid.trim().isEmpty()) {
throw new IllegalArgumentException("userid 不能为空");
}
if (fieldList == null || fieldList.isEmpty()) {
throw new IllegalArgumentException("fieldList 不能为空");
}
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("userid", userid);
jsonObject.add("field_list", WxCpGsonBuilder.create().toJsonTree(fieldList));
this.cpService.post(
this.cpService.getWxCpConfigStorage().getApiUrl(UPDATE_EMPLOYEE_FIELD_INFO),
jsonObject.toString()
);
}
}
View on GitHub (pinned to 1c43293a3c)
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.
Example fix
// before
List<WxCpHrEmployeeFieldData.FieldItem> fields = new ArrayList<>();
// fields may remain empty if nothing to update
service.updateEmployeeFieldInfo(userid, fields); // throws
// after
List<WxCpHrEmployeeFieldData.FieldItem> fields = new ArrayList<>();
// ... populate fields ...
if (!fields.isEmpty()) {
service.updateEmployeeFieldInfo(userid, fields);
} Defensive patterns
Strategy: validation
Validate before calling
if (fieldList == null || fieldList.isEmpty()) {
throw new IllegalArgumentException("fieldList must not be empty");
} Prevention
- 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.
When it happens
Trigger: Calling cpService.getHrService().updateEmployeeFieldInfo(userid, fieldList) where fieldList is null, an empty list, or a list that was cleared after construction.
Common situations: 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.
Related errors
- userid 不能为空
- 更新「联系我」方式需要指定configId
- userid_list和department_id_list至少需要填其中一个
- 文件[{}]不存在
- uri参数中不允许有access_token: {uri}
AI-assisted analysis of binarywang/WxJava@1c43293a3c (2026-08-14).
Data as JSON: /api/errors/ba4d2400a8b07a1a.
Report an issue: GitHub.