alibaba/spring-cloud-alibaba · error · BusinessException
no enough stock
Error message
no enough stock
What it means
Thrown by the private checkStock helper inside StorageServiceImpl.reduceStock. It reads stock via storageMapper.getStock(commodityCode) and throws BusinessException("no enough stock") when stock < count. This is the pre-flight stock check before the deducting UPDATE. Because the UPDATE has no count-guard, this Java-side check is the only thing preventing stock from going negative. Note: getStock returns null if the commodityCode is absent, and `stock < count` would then throw NullPointerException rather than this message.
Source
Thrown at spring-cloud-alibaba-examples/integrated-example/integrated-storage/src/main/java/com/alibaba/cloud/integration/storage/service/impl/StorageServiceImpl.java:72
if (updateCount == 0) {
throw new BusinessException("deduct stock failed");
}
}
@Override
public Result<?> getRemainCount(String commodityCode) {
Integer stock = storageMapper.getStock(commodityCode);
if (stock == null) {
return Result.failed("commodityCode wrong,please check commodity code");
}
return Result.success(stock);
}
private void checkStock(String commodityCode, Integer count)
throws BusinessException {
Integer stock = storageMapper.getStock(commodityCode);
if (stock < count) {
throw new BusinessException("no enough stock");
}
}
}
View on GitHub (pinned to 115d590110)
Solutions
- Check the storage count: SELECT count FROM storage WHERE commodity_code = '<commodityCode>'.
- Replenish: UPDATE storage SET count = <units> WHERE commodity_code = '<commodityCode>'.
- Reduce the requested count to fit available stock.
Example fix
// before
private void checkStock(String commodityCode, Integer count) throws BusinessException {
Integer stock = storageMapper.getStock(commodityCode);
if (stock < count) {
throw new BusinessException("no enough stock");
}
}
// after: guard null to avoid an NPE
private void checkStock(String commodityCode, Integer count) throws BusinessException {
Integer stock = storageMapper.getStock(commodityCode);
if (stock == null) {
throw new BusinessException("commodity not found: " + commodityCode);
}
if (stock < count) {
throw new BusinessException("no enough stock");
}
} Defensive patterns
Strategy: validation
Validate before calling
// Pre-check stock and guard null to avoid an NPE.
Integer stock = storageMapper.getStock(commodityCode);
if (stock == null) {
throw new BusinessException("commodity not found: " + commodityCode);
}
if (stock < count) {
throw new BusinessException("no enough stock");
} Prevention
- Null-check Integer mapper results before comparison.
- Seed stock above the maximum count you will request.
- Note the UPDATE has no count guard, so this Java check is the only floor.
When it happens
Trigger: reduceStock(commodityCode, count) called with count greater than the storage row's count. Reached when the order orchestrator deducts stock for an order whose quantity exceeds available units.
Common situations: Storage seeded with fewer units than requested; prior orders exhausted a commodity; a demo test ordering more than the seeded count.
Related errors
AI-assisted analysis of alibaba/spring-cloud-alibaba@115d590110 (2026-08-14).
Data as JSON: /api/errors/0ab683d2733fd40d.
Report an issue: GitHub.