binarywang/WxJava · warning · IllegalArgumentException
userid 不能为空
Error message
userid 不能为空
What it means
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.
Source
Thrown at weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpHrServiceImpl.java:49
if (fields != null && !fields.isEmpty()) {
jsonObject.add("fields", WxCpGsonBuilder.create().toJsonTree(fields));
}
String response = this.cpService.post(
this.cpService.getWxCpConfigStorage().getApiUrl(GET_FIELD_INFO),
jsonObject.toString()
);
return WxCpHrEmployeeFieldInfoResp.fromJson(response);
}
@Override
public WxCpHrEmployeeFieldDataResp getEmployeeFieldInfo(String userid, List<String> fields) throws WxErrorException {
return getEmployeeFieldInfo(userid, false, fields);
}
@Override
public WxCpHrEmployeeFieldDataResp getEmployeeFieldInfo(String userid, boolean getAll, List<String> fields) throws WxErrorException {
if (userid == null || userid.trim().isEmpty()) {
throw new IllegalArgumentException("userid 不能为空");
}
JsonObject jsonObject = new JsonObject();
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 不能为空");View on GitHub (pinned to 1c43293a3c)
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.
Example fix
// before
String userid = request.getParameter("userid"); // could be null
service.getEmployeeFieldInfo(userid, false, fields); // throws if blank
// after
String userid = request.getParameter("userid");
if (StringUtils.isNotBlank(userid)) {
service.getEmployeeFieldInfo(userid, false, fields);
} Defensive patterns
Strategy: validation
Validate before calling
if (userid == null || userid.trim().isEmpty()) {
throw new IllegalArgumentException("userid must not be blank");
} Prevention
- 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.
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- fieldList 不能为空
- 更新「联系我」方式需要指定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/ff8072b8fb99b576.
Report an issue: GitHub.