paascloud/paascloud-master · error · OmcBizException
OMC10031008
OMC10031008
Error message
OMC10031008
What it means
ErrorCodeEnum.OMC10031008 ('failed to update default address, addressId=%s') is thrown by setDefault when omcShippingMapper.updateByPrimaryKeySelective affects fewer than 1 row while flipping the default-address flag. It means the UPDATE found no matching (or updatable) row for the given addressId.
Solutions
- Validate the addressId exists and belongs to the user before the update (SELECT ... WHERE id = ? AND user_id = ?)
- Catch OmcBizException and inform the user the address no longer exists, refreshing the address list
- Check for soft-delete/flag columns in the mapper's UPDATE WHERE clause that filter out the row
Example fix
// before
result = omcShippingMapper.updateByPrimaryKeySelective(updateNotDefault);
if (result < 1) {
throw new OmcBizException(ErrorCodeEnum.OMC10031008, addressId);
}
// after
OmcShipping owned = omcShippingMapper.selectByPrimaryKey(addressId);
Preconditions.checkState(owned != null && owned.getUserId().equals(userId), "address not owned by user");
result = omcShippingMapper.updateByPrimaryKeySelective(updateNotDefault); Defensive patterns
Strategy: validation
Validate before calling
OmcShipping owned = omcShippingMapper.selectByPrimaryKey(addressId);
if (owned == null || !owned.getUserId().equals(loginAuthDto.getUserId())) {
throw new AddressNotFoundException(addressId);
} Type guard
boolean userOwnsAddress(Long userId, Long addressId) {
OmcShipping s = omcShippingMapper.selectByPrimaryKey(addressId);
return s != null && userId.equals(s.getUserId());
} Try / catch
try {
shippingService.setDefaultAddress(addressId, loginAuthDto);
} catch (OmcBizException e) {
if (e.getCode() == 10031008) { reloadAddressList(); }
else throw e;
} Prevention
- Re-fetch and validate the address right before update to avoid TOCTOU races
- Invalidate stale address ids in the frontend after deletes
- Check the mapper's UPDATE WHERE clause for soft-delete/ownership filters
When it happens
Trigger: setDefault(addressId, isDefault, loginAuthDto) is called with an addressId that does not exist in omc_shipping, belongs to another user, or was deleted between the earlier existence check and the update (TOCTOU race).
Common situations: Concurrent delete of the address while a set-default request is in flight, stale frontend sending an old addressId, or cross-user id from a tampered request.
Related errors
AI-assisted analysis of paascloud/paascloud-master@781281a950 (2026-09-10).
Data as JSON: /api/errors/d1ac3cdc37b7d000.
Report an issue: GitHub.
Appendix: source
Thrown at paascloud-provider/paascloud-provider-omc/src/main/java/com/paascloud/provider/service/impl/OmcShippingServiceImpl.java:133
logger.info("所选地址和当前用户默认地址相同 userId={}, addressId={}", userId, addressId);
return 1;
}
// 3. 相同不处理不相同把当前改为非默认, 把当前地址改为默认地址
setDefault(loginAuthDto, addressId, OmcApiConstant.Shipping.DEFAULT);
setDefault(loginAuthDto, omcShipping.getId(), OmcApiConstant.Shipping.NOT_DEFAULT);
return 1;
}
private void setDefault(LoginAuthDto loginAuthDto, Long addressId, int isDefault) {
int result;
OmcShipping updateNotDefault = new OmcShipping();
updateNotDefault.setDefaultAddress(isDefault);
updateNotDefault.setUpdateInfo(loginAuthDto);
updateNotDefault.setId(addressId);
result = omcShippingMapper.updateByPrimaryKeySelective(updateNotDefault);
if (result < 1) {
throw new OmcBizException(ErrorCodeEnum.OMC10031008, addressId);
}
}
}View on GitHub (pinned to 781281a950)