{"record":{"id":"c979a6002a793aee","repo":"binarywang/WxJava","slug":"agentid","errorCode":null,"errorMessage":"缺少agentid参数","messagePattern":"缺少agentid参数","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpAgentServiceImpl.java","lineNumber":39,"sourceCode":"\n/**\n * <pre>\n *  管理企业号应用\n *  Created by huansinho on 2018/4/13.\n * </pre>\n *\n * @author <a href=\"https://github.com/huansinho\">huansinho</a>\n */\n@RequiredArgsConstructor\npublic class WxCpAgentServiceImpl implements WxCpAgentService {\n\n\n  private final WxCpService mainService;\n\n  @Override\n  public WxCpAgent get(Long agentId) throws WxErrorException {\n    if (agentId == null) {\n      throw new IllegalArgumentException(\"缺少agentid参数\");\n    }\n\n    final String url = String.format(this.mainService.getWxCpConfigStorage().getApiUrl(AGENT_GET), agentId);\n    return WxCpAgent.fromJson(this.mainService.get(url, null));\n  }\n\n  @Override\n  public void set(WxCpAgent agentInfo) throws WxErrorException {\n    String url = this.mainService.getWxCpConfigStorage().getApiUrl(AGENT_SET);\n    String responseContent = this.mainService.post(url, agentInfo.toJson());\n    JsonObject jsonObject = GsonParser.parse(responseContent);\n    if (jsonObject.get(WxConsts.ERR_CODE).getAsInt() != 0) {\n      throw new WxErrorException(WxError.fromJson(responseContent, WxType.CP));\n    }\n  }\n\n  @Override\n  public List<WxCpAgent> list() throws WxErrorException {","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/binarywang/WxJava/blob/1c43293a3c2c9d7e91304b6d037fb017f680d0c6/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpAgentServiceImpl.java#L21-L57","documentation":"Thrown by WxCpAgentServiceImpl.get(Long agentId) when agentId is null. The agentId is required by the AGENT_GET URL template (String.format with %s), so a null would both break the URL and be semantically invalid; the method rejects it with IllegalArgumentException up front.","triggerScenarios":"Calling agentService.get(null) because the agentId was not configured, came from a missing property, or was a null Long from a map/optional.","commonSituations":"Multi-agent app where the agentId is optional/variable and was unset; reading agentId from config that was not provided; passing a Long that was never assigned.","solutions":["Provide a non-null agentId sourced from configuration.","Null-check before calling and fail with a clear domain error if it is missing.","Validate required config at startup so agentId cannot be null at runtime."],"exampleFix":"// before\nWxCpAgent a = agentService.get(agentId); // agentId may be null\n// after\nif (agentId == null) throw new IllegalArgumentException(\"agentId not configured\");\nWxCpAgent a = agentService.get(agentId);","handlingStrategy":"validation","validationCode":"if (agentId == null) throw new IllegalArgumentException(\"agentId not configured\");\nagentService.get(agentId);","typeGuard":"static boolean validAgentId(Long id) { return id != null; }","tryCatchPattern":"null","preventionTips":["Source agentId from validated configuration.","Fail fast at startup if agentId is required but unset.","Null-check dynamic agentId before calling."],"tags":["weixin-api","cp","agent","validation","null-check"],"backgroundTag":null,"analyzedSha":"1c43293a3c2c9d7e91304b6d037fb017f680d0c6","analyzedAt":"2026-08-14T02:29:11.060Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}