{"record":{"id":"7659efb8383c8352","repo":"binarywang/WxJava","slug":"s","errorCode":null,"errorMessage":"必填字段【%s】必须提供值！","messagePattern":"必填字段【(.+?)】必须提供值！","errorType":"exception","errorClass":"WxErrorException","httpStatus":null,"severity":"error","filePath":"weixin-java-common/src/main/java/me/chanjar/weixin/common/util/BeanUtils.java","lineNumber":60,"sourceCode":"          // 另外一种情况是类型为字符串，但是字符串内容为空的，都认为是没有提供值\n          boolean isRequiredMissing = field.get(bean) == null\n            || (field.get(bean) instanceof String\n            && StringUtils.isBlank(field.get(bean).toString())\n          );\n          if (isRequiredMissing) {\n            requiredFields.add(field.getName());\n          }\n        }\n        field.setAccessible(isAccessible);\n      } catch (SecurityException | IllegalArgumentException | IllegalAccessException e) {\n        log.error(e.getMessage(), e);\n      }\n    }\n\n    if (!requiredFields.isEmpty()) {\n      String msg = String.format(\"必填字段【%s】必须提供值！\", requiredFields);\n      log.debug(msg);\n      throw new WxErrorException(msg);\n    }\n  }\n\n}\n","sourceCodeStart":42,"sourceCodeEnd":65,"githubUrl":"https://github.com/binarywang/WxJava/blob/1c43293a3c2c9d7e91304b6d037fb017f680d0c6/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/BeanUtils.java#L42-L65","documentation":"BeanUtils.checkRequiredFields reflects over a bean's fields annotated as required and collects any that are null/empty; if any are missing it throws WxErrorException listing them. This is used to validate request beans before sending them to WeChat, so required fields are enforced client-side with a clear message rather than failing opaquely server-side.","triggerScenarios":"Building a request bean (e.g. a WxMp/Channel/CP request object) and calling an API without populating one or more fields marked as required by the SDK's validation annotations.","commonSituations":"A new required field added in a WxJava upgrade that existing bean-construction code does not set; conditional logic that skips setting a required field for a particular request variant; copy-paste bean construction omitting a field.","solutions":["Inspect the exception message — it names the exact missing required field(s).","Populate the listed field(s) on the bean before retrying the API call.","Use a builder/factory that enforces required fields at construction time.","After WxJava upgrades, diff request beans for newly-required fields."],"exampleFix":"// before — required field 'appId' left null\nWxSomeRequest req = new WxSomeRequest();\nreq.setSecret(secret);\nservice.doSomething(req); // throws: 必填字段【appId】必须提供值！\n\n// after\nWxSomeRequest req = new WxSomeRequest();\nreq.setAppId(appId);\nreq.setSecret(secret);\nservice.doSomething(req);","handlingStrategy":"validation","validationCode":"// Validate required fields before the call — let BeanUtils name them,\n// or pre-check known required fields:\nif (req.getAppId() == null || req.getSecret() == null) {\n  throw new IllegalArgumentException(\"appId/secret required\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  service.doSomething(req);\n} catch (WxErrorException e) {\n  if (e.getMessage() != null && e.getMessage().contains(\"必填字段\")) {\n    // message names the missing field(s) — populate and retry\n  }\n  throw e;\n}","preventionTips":["Read the exception message — it lists the exact missing required field(s).","Use a builder/factory that enforces required fields at construction.","After WxJava upgrades, diff request beans for newly-required fields."],"tags":["validation","required-field","bean","request-build"],"backgroundTag":null,"analyzedSha":"1c43293a3c2c9d7e91304b6d037fb017f680d0c6","analyzedAt":"2026-08-14T02:29:11.060Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}