{"record":{"id":"d1ac3cdc37b7d000","repo":"paascloud/paascloud-master","slug":"omc10031008","errorCode":"OMC10031008","errorMessage":"OMC10031008","messagePattern":"OMC10031008","errorType":"error_code","errorClass":"OmcBizException","httpStatus":null,"severity":"error","filePath":"paascloud-provider/paascloud-provider-omc/src/main/java/com/paascloud/provider/service/impl/OmcShippingServiceImpl.java","lineNumber":133,"sourceCode":"\t\t\tlogger.info(\"所选地址和当前用户默认地址相同 userId={}, addressId={}\", userId, addressId);\n\t\t\treturn 1;\n\t\t}\n\t\t// 3. 相同不处理不相同把当前改为非默认, 把当前地址改为默认地址\n\t\tsetDefault(loginAuthDto, addressId, OmcApiConstant.Shipping.DEFAULT);\n\t\tsetDefault(loginAuthDto, omcShipping.getId(), OmcApiConstant.Shipping.NOT_DEFAULT);\n\n\t\treturn 1;\n\t}\n\n\tprivate void setDefault(LoginAuthDto loginAuthDto, Long addressId, int isDefault) {\n\t\tint result;\n\t\tOmcShipping updateNotDefault = new OmcShipping();\n\t\tupdateNotDefault.setDefaultAddress(isDefault);\n\t\tupdateNotDefault.setUpdateInfo(loginAuthDto);\n\t\tupdateNotDefault.setId(addressId);\n\t\tresult = omcShippingMapper.updateByPrimaryKeySelective(updateNotDefault);\n\t\tif (result < 1) {\n\t\t\tthrow new OmcBizException(ErrorCodeEnum.OMC10031008, addressId);\n\t\t}\n\t}\n}","sourceCodeStart":115,"sourceCodeEnd":136,"githubUrl":"https://github.com/paascloud/paascloud-master/blob/781281a9503332ed3cef44ea618349d14230a127/paascloud-provider/paascloud-provider-omc/src/main/java/com/paascloud/provider/service/impl/OmcShippingServiceImpl.java#L115-L136","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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"],"exampleFix":"// before\nresult = omcShippingMapper.updateByPrimaryKeySelective(updateNotDefault);\nif (result < 1) {\n    throw new OmcBizException(ErrorCodeEnum.OMC10031008, addressId);\n}\n// after\nOmcShipping owned = omcShippingMapper.selectByPrimaryKey(addressId);\nPreconditions.checkState(owned != null && owned.getUserId().equals(userId), \"address not owned by user\");\nresult = omcShippingMapper.updateByPrimaryKeySelective(updateNotDefault);","handlingStrategy":"validation","validationCode":"OmcShipping owned = omcShippingMapper.selectByPrimaryKey(addressId);\nif (owned == null || !owned.getUserId().equals(loginAuthDto.getUserId())) {\n    throw new AddressNotFoundException(addressId);\n}","typeGuard":"boolean userOwnsAddress(Long userId, Long addressId) {\n    OmcShipping s = omcShippingMapper.selectByPrimaryKey(addressId);\n    return s != null && userId.equals(s.getUserId());\n}","tryCatchPattern":"try {\n    shippingService.setDefaultAddress(addressId, loginAuthDto);\n} catch (OmcBizException e) {\n    if (e.getCode() == 10031008) { reloadAddressList(); }\n    else throw e;\n}","preventionTips":["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"],"tags":["shipping-address","update-failed","database"],"backgroundTag":"database-write-failed","analyzedSha":"781281a9503332ed3cef44ea618349d14230a127","analyzedAt":"2026-09-10T10:59:02.070Z","contentChangedAt":"2026-09-10T10:59:02.070Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}