{"record":{"id":"00f3f47c5462d219","repo":"binarywang/WxJava","slug":"error-00f3f4","errorCode":null,"errorMessage":"表单字段名不能为空","messagePattern":"表单字段名不能为空","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"warning","filePath":"weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/CommonUploadParam.java","lineNumber":93,"sourceCode":"   * @param name  参数名，如：media\n   * @param bytes 字节数组\n   * @return 文件上传参数对象\n   */\n  @SneakyThrows\n  public static CommonUploadParam fromBytes(String name, @Nullable String fileName, byte[] bytes) {\n    return new CommonUploadParam(name, new CommonUploadData(fileName, new ByteArrayInputStream(bytes), bytes.length), null);\n  }\n\n  /**\n   * 添加额外的表单字段\n   *\n   * @param fieldName  表单字段名\n   * @param fieldValue 表单字段值\n   * @return 当前对象，支持链式调用\n   */\n  public CommonUploadParam addFormField(String fieldName, String fieldValue) {\n    if (fieldName == null || fieldName.trim().isEmpty()) {\n      throw new IllegalArgumentException(\"表单字段名不能为空\");\n    }\n    if (fieldValue == null) {\n      throw new IllegalArgumentException(\"表单字段值不能为null\");\n    }\n    if (this.formFields == null) {\n      this.formFields = new HashMap<>();\n    }\n    this.formFields.put(fieldName, fieldValue);\n    return this;\n  }\n\n  @Override\n  public String toString() {\n    return String.format(\"{name:%s, data:%s, formFields:%s}\", name, data, formFields);\n  }\n}\n","sourceCodeStart":75,"sourceCodeEnd":110,"githubUrl":"https://github.com/binarywang/WxJava/blob/1c43293a3c2c9d7e91304b6d037fb017f680d0c6/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/CommonUploadParam.java#L75-L110","documentation":"CommonUploadParam.addFormField rejects a null or blank (whitespace-only) field name before adding it to the multipart form. This is a defensive precondition: a multipart part needs a non-empty name to be meaningful and to be accepted by WeChat endpoints.","triggerScenarios":"Calling addFormField(null, value) or addFormField(\"   \", value) while building a CommonUploadParam for an upload request.","commonSituations":"Field name read from a config/properties file that resolved to null or unset; dynamically generated field names where the generator returned empty; copy-paste leaving a placeholder blank.","solutions":["Ensure the field name is a non-blank literal or sourced from validated config.","If the field is optional, skip the addFormField call entirely instead of passing an empty name.","Add a guard/log before the call to catch null or blank names during development."],"exampleFix":"// before\nparam.addFormField(System.getProperty(\"form.field\"), value); // null if unset\n\n// after\nString name = System.getProperty(\"form.field\");\nif (name != null && !name.trim().isEmpty()) {\n  param.addFormField(name, value);\n}","handlingStrategy":"validation","validationCode":"if (fieldName == null || fieldName.trim().isEmpty()) {\n  // skip optional field, or throw a clearer domain error\n} else {\n  param.addFormField(fieldName, fieldValue);\n}","typeGuard":null,"tryCatchPattern":"try {\n  param.addFormField(name, value);\n} catch (IllegalArgumentException e) {\n  if (e.getMessage().contains(\"表单字段名不能为空\")) {\n    // fix or skip the field\n  }\n  throw e;\n}","preventionTips":["Source field names from constants/enums rather than dynamic lookups that can return null.","Guard dynamic field names with a non-blank check before calling addFormField.","Skip the call for optional fields instead of passing an empty name."],"tags":["validation","upload","form-field","precondition"],"backgroundTag":null,"analyzedSha":"1c43293a3c2c9d7e91304b6d037fb017f680d0c6","analyzedAt":"2026-08-14T02:29:11.060Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}