{"record":{"id":"51e245d4d25ebf45","repo":"binarywang/WxJava","slug":"flowtype-1-2-3","errorCode":null,"errorMessage":"查询请求 flowType 不正确，只能是1、2、3之一","messagePattern":"查询请求 flowType 不正确，只能是1、2、3之一","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"warning","filePath":"weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaIntracityServiceImpl.java","lineNumber":142,"sourceCode":"  }\n\n  @Override\n  public int storeRefund(WxMaStoreRefundRequest request) throws WxErrorException {\n    String response = this.wxMaService.postWithSignature(Intracity.STORE_REFUND, request);\n    Map<?, ?> map = gson.fromJson(response, Map.class);\n    return ((Number) map.get(\"refund_amount\")).intValue();\n  }\n\n  @Override\n  public WxMaStoreFlowResponse<? extends WxMaStoreFlowResponse.BasicFlowRecord> queryFlow(\n      WxMaQueryFlowRequest request) throws WxErrorException {\n    if (request == null || request.getWxStoreId() == null) {\n      throw new IllegalArgumentException(\"查询请求 wxStoreId 不可为空\");\n    }\n    WxMaStoreFlowResponse<? extends WxMaStoreFlowResponse.BasicFlowRecord> inst =\n        getFlowInstanceByType(request.getFlowType());\n    if (inst == null) {\n      throw new IllegalArgumentException(\"查询请求 flowType 不正确，只能是1、2、3之一\");\n    }\n\n    String response = this.wxMaService.postWithSignature(Intracity.QUERY_FLOW, request);\n\n    WxMaStoreFlowResponse<? extends WxMaStoreFlowResponse.BasicFlowRecord> flowResponse;\n    flowResponse =\n        (WxMaStoreFlowResponse<? extends WxMaStoreFlowResponse.BasicFlowRecord>)\n            gson.fromJson(response, inst.getClass());\n    logger.debug(\"queryFlow: {}\", flowResponse);\n    return flowResponse;\n  }\n\n  private WxMaStoreFlowResponse<? extends WxMaStoreFlowResponse.BasicFlowRecord>\n      getFlowInstanceByType(int flowType) {\n    WxMaStoreFlowResponse<? extends WxMaStoreFlowResponse.BasicFlowRecord> inst;\n    if (flowType == 1) {\n      inst = new WxMaStoreFlowResponse<WxMaStoreFlowResponse.ChargeFlowRecord>();\n    } else if (flowType == 2) {","sourceCodeStart":124,"sourceCodeEnd":160,"githubUrl":"https://github.com/binarywang/WxJava/blob/1c43293a3c2c9d7e91304b6d037fb017f680d0c6/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaIntracityServiceImpl.java#L124-L160","documentation":"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.","triggerScenarios":"Calling req.setFlowType(0), setFlowType(4), or any int outside {1,2,3} before queryFlow.","commonSituations":"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.","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."],"exampleFix":"// before\nreq.setFlowType(0); // 0-indexed mistake\n\n// after\nreq.setFlowType(1); // 1=充值 2=消费 3=退款","handlingStrategy":"validation","validationCode":"if (flowType < 1 || flowType > 3) {\n  throw new IllegalArgumentException(\"flowType must be 1, 2, or 3\");\n}","typeGuard":"// Java — narrow your own enum so only valid ints exist\nenum FlowType {\n  CHARGE(1), CONSUME(2), REFUND(3);\n  final int v;\n  FlowType(int v) { this.v = v; }\n}","tryCatchPattern":"try {\n  resp = intracityService.queryFlow(req);\n} catch (IllegalArgumentException e) {\n  throw e;\n}","preventionTips":["Wrap flowType in an enum so only valid values compile.","Reject out-of-range flowType at the boundary that feeds WxMaQueryFlowRequest."],"tags":["validation","intracity","query-flow","illegal-argument","enum-range"],"backgroundTag":null,"analyzedSha":"1c43293a3c2c9d7e91304b6d037fb017f680d0c6","analyzedAt":"2026-08-14T02:29:11.060Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}