binarywang/WxJava · warning · IllegalArgumentException

创建门店时outStoreId不能为空

Error message

创建门店时outStoreId不能为空

What it means

Unchecked IllegalArgumentException from createStore(WxMaStore) when store.getOutStoreId() is null. outStoreId is the merchant-defined store identifier required on creation because WeChat does not assign it; wxStoreId is WeChat-assigned (returned on query) and is not a substitute.

Source

Thrown at weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaIntracityServiceImpl.java:49

          .create();

  private void checkStringResponse(String response) throws WxErrorException {
    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());

View on GitHub (pinned to 1c43293a3c)

Solutions

  1. Set outStoreId before calling createStore: store.setOutStoreId("your-unique-store-id").
  2. Validate outStoreId presence in your own DTO/form layer before constructing the WxMaStore.

Example fix

// before
WxMaStore store = new WxMaStore();
store.setStoreName("门店A");
intracityService.createStore(store);

// after
WxMaStore store = new WxMaStore();
store.setOutStoreId("STORE_001");
store.setStoreName("门店A");
intracityService.createStore(store);
Defensive patterns

Strategy: validation

Validate before calling

if (store.getOutStoreId() == null) {
  throw new IllegalArgumentException("outStoreId required before createStore");
}

Try / catch

try {
  id = intracityService.createStore(store);
} catch (IllegalArgumentException e) {
  // bad input — fix the caller, do not retry
  throw e;
}

Prevention

When it happens

Trigger: Calling intracityService.createStore(store) on a WxMaStore whose setOutStoreId(...) was never invoked.

Common situations: Building a WxMaStore from form/JSON input that omitted outStoreId; copying a store bean from a query result (which carries wxStoreId but may have a null outStoreId) and trying to create with it.

Related errors


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