{"record":{"id":"bbd20e16e276b9e9","repo":"binarywang/WxJava","slug":"wxstoreid-null","errorCode":null,"errorMessage":"创建门店时wxStoreId只能是null","messagePattern":"创建门店时wxStoreId只能是null","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"warning","filePath":"weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaIntracityServiceImpl.java","lineNumber":52,"sourceCode":"    JsonObject respObj = GsonParser.parse(response);\n    if (respObj.get(ERR_CODE).getAsInt() != 0) {\n      throw new WxErrorException(WxError.fromJson(response, WxType.MiniApp));\n    }\n  }\n\n  @Override\n  public void apply() throws WxErrorException {\n    String response = this.wxMaService.post(Intracity.APPLY_URL, \"{}\");\n    checkStringResponse(response);\n  }\n\n  @Override\n  public String createStore(WxMaStore store) throws WxErrorException {\n    if (store.getOutStoreId() == null) {\n      throw new IllegalArgumentException(\"创建门店时outStoreId不能为空\");\n    }\n    if (store.getWxStoreId() != null) {\n      throw new IllegalArgumentException(\"创建门店时wxStoreId只能是null\");\n    }\n    String response = this.wxMaService.postWithSignature(Intracity.CREATE_STORE_URL, store);\n    Map<?, ?> map = gson.fromJson(response, Map.class);\n    return (String) map.get(\"wx_store_id\");\n  }\n\n  @Override\n  public void updateStore(WxMaStore store) throws WxErrorException {\n    if (store.getWxStoreId() == null && store.getOutStoreId() == null) {\n      throw new IllegalArgumentException(\"更新门店时wxStoreId 或 outStoreId 至少要有一个不为null\");\n    }\n    JsonObject request = new JsonObject();\n    Map<String, String> keys = new HashMap<>();\n    if (store.getWxStoreId() != null) {\n      keys.put(\"wx_store_id\", store.getWxStoreId());\n    } else {\n      keys.put(\"out_store_id\", store.getOutStoreId());\n    }","sourceCodeStart":34,"sourceCodeEnd":70,"githubUrl":"https://github.com/binarywang/WxJava/blob/1c43293a3c2c9d7e91304b6d037fb017f680d0c6/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaIntracityServiceImpl.java#L34-L70","documentation":"Unchecked IllegalArgumentException from createStore(WxMaStore) when store.getWxStoreId() != null. wxStoreId is assigned by WeChat on creation, so supplying one implies creating a store that already exists in WeChat's system, which is disallowed. The guard keeps create vs update semantics distinct.","triggerScenarios":"Reusing a WxMaStore that already has wxStoreId (e.g. obtained from queryStoreByWxStoreId or listAllStores) and passing it to createStore instead of updateStore.","commonSituations":"Query then modify then accidentally call createStore instead of updateStore; deserializing a persisted WxMaStore JSON that contains wxStoreId and re-creating from it.","solutions":["If you intended to create a NEW store, use a fresh WxMaStore and leave wxStoreId null.","If you meant to modify an EXISTING store, call intracityService.updateStore(store) instead of createStore.","Never round-trip a query result into a create payload — build create payloads separately."],"exampleFix":"// before\nintracityService.createStore(existingStoreFromQuery);\n\n// after\nintracityService.updateStore(existingStoreFromQuery);","handlingStrategy":"validation","validationCode":"if (store.getWxStoreId() != null) {\n  throw new IllegalStateException(\"use updateStore for existing stores\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  id = intracityService.createStore(store);\n} catch (IllegalArgumentException e) {\n  // distinguish create-vs-update misuse\n  throw e;\n}","preventionTips":["Branch on store.getWxStoreId() != null → updateStore; else createStore.","Never reuse a query-result WxMaStore as a create payload."],"tags":["validation","intracity","store","create-vs-update","illegal-argument"],"backgroundTag":null,"analyzedSha":"1c43293a3c2c9d7e91304b6d037fb017f680d0c6","analyzedAt":"2026-08-14T02:29:11.060Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}