{"record":{"id":"66f93d307dbb70ad","repo":"binarywang/WxJava","slug":"wxstoreid-outstoreid-null","errorCode":null,"errorMessage":"更新门店时wxStoreId 或 outStoreId 至少要有一个不为null","messagePattern":"更新门店时wxStoreId 或 outStoreId 至少要有一个不为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":62,"sourceCode":"  }\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    }\n    request.add(\"keys\", gson.toJsonTree(keys));\n    Map<String, Object> updateContent = new HashMap<>();\n    if (store.getStoreName() != null) {\n      updateContent.put(\"store_name\", store.getStoreName());\n    }\n    if (store.getOrderPattern() == 1 || store.getOrderPattern() == 2) {\n      updateContent.put(\"order_pattern\", store.getOrderPattern());\n    }\n    if (store.getServiceTransPrefer() != null) {\n      updateContent.put(\"service_trans_prefer\", store.getServiceTransPrefer());","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/binarywang/WxJava/blob/1c43293a3c2c9d7e91304b6d037fb017f680d0c6/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaIntracityServiceImpl.java#L44-L80","documentation":"Unchecked IllegalArgumentException from updateStore(WxMaStore) when both wxStoreId and outStoreId are null. updateStore builds a 'keys' map to identify the target store via exactly one of these IDs; without either, the update target is ambiguous so it aborts before the HTTP call.","triggerScenarios":"Calling intracityService.updateStore(store) on a WxMaStore with neither identifier set.","commonSituations":"Constructing a new WxMaStore, setting only mutable fields (storeName, orderPattern) and forgetting the identifier; a partial-update DTO that dropped the id field during mapping.","solutions":["Set at least one identifier — preferably store.setWxStoreId(id) using the id from the create/query result, or store.setOutStoreId(merchantId).","Carry the identifier through your update flow from the original create/query response."],"exampleFix":"// before\nWxMaStore s = new WxMaStore();\ns.setStoreName(\"new name\");\nintracityService.updateStore(s);\n\n// after\nWxMaStore s = new WxMaStore();\ns.setWxStoreId(wxStoreIdFromCreate);\ns.setStoreName(\"new name\");\nintracityService.updateStore(s);","handlingStrategy":"validation","validationCode":"if (store.getWxStoreId() == null && store.getOutStoreId() == null) {\n  throw new IllegalArgumentException(\"need wxStoreId or outStoreId to update\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  intracityService.updateStore(store);\n} catch (IllegalArgumentException e) {\n  throw e;\n}","preventionTips":["Always retain the wxStoreId returned by createStore for subsequent updates.","Validate identifier presence in your update DTO before mapping to WxMaStore."],"tags":["validation","intracity","store","update","illegal-argument","null-check"],"backgroundTag":null,"analyzedSha":"1c43293a3c2c9d7e91304b6d037fb017f680d0c6","analyzedAt":"2026-08-14T02:29:11.060Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}