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

  1. If you intended to create a NEW store, use a fresh WxMaStore and leave wxStoreId null.
  2. If you meant to modify an EXISTING store, call intracityService.updateStore(store) instead of createStore.
  3. 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

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


AI-assisted analysis of binarywang/WxJava@1c43293a3c (2026-08-14). Data as JSON: /api/errors/bbd20e16e276b9e9. Report an issue: GitHub.