binarywang/WxJava · warning · IllegalArgumentException
创建门店时wxStoreId只能是null
Error message
创建门店时wxStoreId只能是null
What it means
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.
Source
Thrown at weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaIntracityServiceImpl.java:52
JsonObject respObj = GsonParser.parse(response);
if (respObj.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(response, WxType.MiniApp));
}
}
@Override
public void apply() throws WxErrorException {
String response = this.wxMaService.post(Intracity.APPLY_URL, "{}");
checkStringResponse(response);
}
@Override
public String createStore(WxMaStore store) throws WxErrorException {
if (store.getOutStoreId() == null) {
throw new IllegalArgumentException("创建门店时outStoreId不能为空");
}
if (store.getWxStoreId() != null) {
throw new IllegalArgumentException("创建门店时wxStoreId只能是null");
}
String response = this.wxMaService.postWithSignature(Intracity.CREATE_STORE_URL, store);
Map<?, ?> map = gson.fromJson(response, Map.class);
return (String) map.get("wx_store_id");
}
@Override
public void updateStore(WxMaStore store) throws WxErrorException {
if (store.getWxStoreId() == null && store.getOutStoreId() == null) {
throw new IllegalArgumentException("更新门店时wxStoreId 或 outStoreId 至少要有一个不为null");
}
JsonObject request = new JsonObject();
Map<String, String> keys = new HashMap<>();
if (store.getWxStoreId() != null) {
keys.put("wx_store_id", store.getWxStoreId());
} else {
keys.put("out_store_id", store.getOutStoreId());
}View on GitHub (pinned to 1c43293a3c)
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.
Example fix
// before intracityService.createStore(existingStoreFromQuery); // after intracityService.updateStore(existingStoreFromQuery);
Defensive patterns
Strategy: validation
Validate before calling
if (store.getWxStoreId() != null) {
throw new IllegalStateException("use updateStore for existing stores");
} Try / catch
try {
id = intracityService.createStore(store);
} catch (IllegalArgumentException e) {
// distinguish create-vs-update misuse
throw e;
} Prevention
- Branch on store.getWxStoreId() != null → updateStore; else createStore.
- Never reuse a query-result WxMaStore as a create payload.
When it happens
Trigger: Reusing a WxMaStore that already has wxStoreId (e.g. obtained from queryStoreByWxStoreId or listAllStores) and passing it to createStore instead of updateStore.
Common situations: Query then modify then accidentally call createStore instead of updateStore; deserializing a persisted WxMaStore JSON that contains wxStoreId and re-creating from it.
Related errors
- 创建门店时outStoreId不能为空
- 更新门店时wxStoreId 或 outStoreId 至少要有一个不为null
- 查询请求 wxStoreId 不可为空
- 查询请求 flowType 不正确,只能是1、2、3之一
- payMode是PAY_MODE_STORE或null时,必须传递wxStoreId
AI-assisted analysis of binarywang/WxJava@1c43293a3c (2026-08-14).
Data as JSON: /api/errors/bbd20e16e276b9e9.
Report an issue: GitHub.