{"record":{"id":"52a69ca1523f04d3","repo":"binarywang/WxJava","slug":"null","errorCode":null,"errorMessage":"表单字段值不能为null","messagePattern":"表单字段值不能为null","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"warning","filePath":"weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/CommonUploadParam.java","lineNumber":96,"sourceCode":"   */\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":78,"sourceCodeEnd":110,"githubUrl":"https://github.com/binarywang/WxJava/blob/1c43293a3c2c9d7e91304b6d037fb017f680d0c6/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/CommonUploadParam.java#L78-L110","documentation":"CommonUploadParam.addFormField rejects a null field value. Unlike a blank name, the method treats null value as a programming error — to remove a field you omit the call, not pass null. This prevents silent malformed multipart bodies.","triggerScenarios":"Calling addFormField(name, null) where the value resolved to null (e.g. an unset map entry, a missing config value, or an uninitialised variable).","commonSituations":"Value looked up from a Map/properties that returned null; an upstream computation that can legitimately produce null but the caller forwarded it unconditionally.","solutions":["Coalesce null values to an empty string (\"\") if an empty part is acceptable, or skip the field if it is optional.","Validate/require the value at the source so null never reaches addFormField.","Log when a value is null so you can decide skip-vs-default behaviour intentionally."],"exampleFix":"// before\nparam.addFormField(\"openid\", userInfo.getOpenid()); // null if missing\n\n// after\nString openid = userInfo.getOpenid();\nif (openid != null) {\n  param.addFormField(\"openid\", openid);\n}","handlingStrategy":"validation","validationCode":"if (fieldValue == null) {\n  // skip optional field, or default to empty string\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(\"表单字段值不能为null\")) {\n    // default to \"\" or skip\n  }\n  throw e;\n}","preventionTips":["Coalesce null values to \"\" only if an empty part is acceptable; otherwise skip the field.","Validate upstream sources so null never reaches addFormField.","Use Optional/Objects.requireNonNull at the data source to fail early."],"tags":["validation","upload","form-field","null-value"],"backgroundTag":null,"analyzedSha":"1c43293a3c2c9d7e91304b6d037fb017f680d0c6","analyzedAt":"2026-08-14T02:29:11.060Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}