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

  1. Check fieldList is non-empty before calling: if (fieldList == null || fieldList.isEmpty()) skip the update.
  2. Ensure at least one FieldItem is always added when constructing the list for the update call.
  3. 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

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


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