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

  1. Validate userid is non-blank before calling: if (StringUtils.isBlank(userid)) skip or log and continue.
  2. Ensure the upstream data source that provides userid is filtered for nulls/empties.
  3. 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

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


AI-assisted analysis of binarywang/WxJava@1c43293a3c (2026-08-14). Data as JSON: /api/errors/ff8072b8fb99b576. Report an issue: GitHub.