{"record":{"id":"aa1464a394ccf624","repo":"alibaba/spring-cloud-alibaba","slug":"no-enough-balance","errorCode":null,"errorMessage":"no enough balance","messagePattern":"no enough balance","errorType":"exception","errorClass":"BusinessException","httpStatus":null,"severity":"error","filePath":"spring-cloud-alibaba-examples/integrated-example/integrated-account/src/main/java/com/alibaba/cloud/integration/account/service/impl/AccountServiceImpl.java","lineNumber":70,"sourceCode":"\t\tint updateCount = accountMapper.reduceBalance(userId, price, updateTime);\n\t\tif (updateCount == 0) {\n\t\t\tthrow new BusinessException(\"reduce balance failed\");\n\t\t}\n\t}\n\n\t@Override\n\tpublic Result<?> getRemainAccount(String userId) {\n\t\tInteger balance = accountMapper.getBalance(userId);\n\t\tif (balance == null) {\n\t\t\treturn Result.failed(\"wrong userId,please check the userId\");\n\t\t}\n\t\treturn Result.success(balance);\n\t}\n\n\tprivate void checkBalance(String userId, Integer price) throws BusinessException {\n\t\tInteger balance = accountMapper.getBalance(userId);\n\t\tif (balance < price) {\n\t\t\tthrow new BusinessException(\"no enough balance\");\n\t\t}\n\t}\n\n}\n","sourceCodeStart":52,"sourceCodeEnd":75,"githubUrl":"https://github.com/alibaba/spring-cloud-alibaba/blob/115d5901102009492e05d5ec18c3f79cad4077d0/spring-cloud-alibaba-examples/integrated-example/integrated-account/src/main/java/com/alibaba/cloud/integration/account/service/impl/AccountServiceImpl.java#L52-L75","documentation":"Thrown by the private checkBalance helper inside AccountServiceImpl.reduceBalance. It reads the current money via accountMapper.getBalance(userId) and throws BusinessException(\"no enough balance\") when balance < price. This is the explicit pre-flight balance check that runs before the deducting UPDATE. Note: balance is an Integer from the DB; if the userId has no row, getBalance returns null and the comparison `balance < price` throws NullPointerException instead of this message.","triggerScenarios":"reduceBalance(userId, price) called with a price larger than the account's current money (e.g., order quantity * unit price exceeds funds). Reached from the order service when accountService.reduceBalance is invoked after stock deduction.","commonSituations":"Account table seeded with too little money for the demo (e.g., money=0 or a small value); a test that orders more units than the balance covers; price computed as count*2 in OrderServiceImpl exceeding the seeded balance.","solutions":["Inspect/raise the account row money: UPDATE account SET money = <larger value> WHERE user_id = '<userId>'.","Reduce the order count so count*2 stays within the available balance.","Confirm the userId matches a seeded account row to avoid the separate NullPointerException path."],"exampleFix":"// before\nprivate void checkBalance(String userId, Integer price) throws BusinessException {\n    Integer balance = accountMapper.getBalance(userId);\n    if (balance < price) {\n        throw new BusinessException(\"no enough balance\");\n    }\n}\n// after: guard the null case to avoid an NPE masking the real cause\nprivate void checkBalance(String userId, Integer price) throws BusinessException {\n    Integer balance = accountMapper.getBalance(userId);\n    if (balance == null) {\n        throw new BusinessException(\"account not found: \" + userId);\n    }\n    if (balance < price) {\n        throw new BusinessException(\"no enough balance\");\n    }\n}","handlingStrategy":"validation","validationCode":"// Validate funds before deducting, and guard null to avoid a hidden NPE.\nInteger balance = accountMapper.getBalance(userId);\nif (balance == null || balance < price) {\n    // surface a clear 'insufficient funds' / 'no account' result instead of deducting\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always null-check Integer results from mappers before comparison.","Seed account money so count*2 (the order price) is affordable.","Expose a getBalance-style endpoint for clients to pre-check funds."],"tags":["seata","distributed-transaction","business-rule","account","validation"],"backgroundTag":null,"analyzedSha":"115d5901102009492e05d5ec18c3f79cad4077d0","analyzedAt":"2026-08-14T04:47:13.900Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}