binarywang/WxJava · warning · IllegalArgumentException
查询请求 flowType 不正确,只能是1、2、3之一
Error message
查询请求 flowType 不正确,只能是1、2、3之一
What it means
Unchecked IllegalArgumentException from queryFlow when getFlowInstanceByType(flowType) returns null, i.e. flowType is not 1 (充值/recharge), 2 (消费/consume), or 3 (退款/refund). The helper maps each value to a typed WxMaStoreFlowResponse<X> so the response deserializes to the correct record type. The bean's flowType field defaults to 1, so you must explicitly assign an out-of-range int to trigger this.
Source
Thrown at weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaIntracityServiceImpl.java:142
}
@Override
public int storeRefund(WxMaStoreRefundRequest request) throws WxErrorException {
String response = this.wxMaService.postWithSignature(Intracity.STORE_REFUND, request);
Map<?, ?> map = gson.fromJson(response, Map.class);
return ((Number) map.get("refund_amount")).intValue();
}
@Override
public WxMaStoreFlowResponse<? extends WxMaStoreFlowResponse.BasicFlowRecord> queryFlow(
WxMaQueryFlowRequest request) throws WxErrorException {
if (request == null || request.getWxStoreId() == null) {
throw new IllegalArgumentException("查询请求 wxStoreId 不可为空");
}
WxMaStoreFlowResponse<? extends WxMaStoreFlowResponse.BasicFlowRecord> inst =
getFlowInstanceByType(request.getFlowType());
if (inst == null) {
throw new IllegalArgumentException("查询请求 flowType 不正确,只能是1、2、3之一");
}
String response = this.wxMaService.postWithSignature(Intracity.QUERY_FLOW, request);
WxMaStoreFlowResponse<? extends WxMaStoreFlowResponse.BasicFlowRecord> flowResponse;
flowResponse =
(WxMaStoreFlowResponse<? extends WxMaStoreFlowResponse.BasicFlowRecord>)
gson.fromJson(response, inst.getClass());
logger.debug("queryFlow: {}", flowResponse);
return flowResponse;
}
private WxMaStoreFlowResponse<? extends WxMaStoreFlowResponse.BasicFlowRecord>
getFlowInstanceByType(int flowType) {
WxMaStoreFlowResponse<? extends WxMaStoreFlowResponse.BasicFlowRecord> inst;
if (flowType == 1) {
inst = new WxMaStoreFlowResponse<WxMaStoreFlowResponse.ChargeFlowRecord>();
} else if (flowType == 2) {View on GitHub (pinned to 1c43293a3c)
Solutions
- Use only 1, 2, or 3 (1=充值, 2=消费, 3=退款) — preferably via a local enum you control.
- Validate flowType is in {1,2,3} before setting it on the request.
Example fix
// before req.setFlowType(0); // 0-indexed mistake // after req.setFlowType(1); // 1=充值 2=消费 3=退款
Defensive patterns
Strategy: validation
Validate before calling
if (flowType < 1 || flowType > 3) {
throw new IllegalArgumentException("flowType must be 1, 2, or 3");
} Type guard
// Java — narrow your own enum so only valid ints exist
enum FlowType {
CHARGE(1), CONSUME(2), REFUND(3);
final int v;
FlowType(int v) { this.v = v; }
} Try / catch
try {
resp = intracityService.queryFlow(req);
} catch (IllegalArgumentException e) {
throw e;
} Prevention
- Wrap flowType in an enum so only valid values compile.
- Reject out-of-range flowType at the boundary that feeds WxMaQueryFlowRequest.
When it happens
Trigger: Calling req.setFlowType(0), setFlowType(4), or any int outside {1,2,3} before queryFlow.
Common situations: Mapping an external 0-indexed enum/integer to flowType; copying a sample that used the wrong value; assigning a value read from config without range validation.
Related errors
- 查询请求 wxStoreId 不可为空
- 创建门店时outStoreId不能为空
- 创建门店时wxStoreId只能是null
- 更新门店时wxStoreId 或 outStoreId 至少要有一个不为null
- payMode是PAY_MODE_STORE或null时,必须传递wxStoreId
AI-assisted analysis of binarywang/WxJava@1c43293a3c (2026-08-14).
Data as JSON: /api/errors/51e245d4d25ebf45.
Report an issue: GitHub.