{"record":{"id":"19243325b63c622f","repo":"paascloud/paascloud-master","slug":"uac10012001-192433","errorCode":"UAC10012001","errorMessage":"角色ID不能为空","messagePattern":"角色ID不能为空","errorType":"error_code","errorClass":"UacBizException","httpStatus":null,"severity":"error","filePath":"paascloud-provider/paascloud-provider-uac/src/main/java/com/paascloud/provider/service/impl/UacRoleMenuServiceImpl.java","lineNumber":39,"sourceCode":"@Service\n@Transactional(rollbackFor = Exception.class)\npublic class UacRoleMenuServiceImpl extends BaseService<UacRoleMenu> implements UacRoleMenuService {\n\t@Resource\n\tprivate UacRoleMenuMapper uacRoleMenuMapper;\n\n\t@Override\n\tpublic int delRoleMenuList(Set<UacRoleMenu> uacRoleMenus) {\n\t\tint result = 0;\n\t\tfor (UacRoleMenu uacRoleMenu : uacRoleMenus) {\n\t\t\tresult += uacRoleMenuMapper.delete(uacRoleMenu);\n\t\t}\n\t\treturn result;\n\t}\n\n\t@Override\n\tpublic void deleteByRoleId(Long roleId) {\n\t\tif (roleId == null) {\n\t\t\tthrow new UacBizException(ErrorCodeEnum.UAC10012001);\n\t\t}\n\t\tUacRoleMenu roleMenu = new UacRoleMenu();\n\t\troleMenu.setRoleId(roleId);\n\t\tuacRoleMenuMapper.delete(roleMenu);\n\t}\n\n\t@Override\n\t@Transactional(readOnly = true, rollbackFor = Exception.class)\n\tpublic List<UacRoleMenu> listByRoleId(Long roleId) {\n\t\tif (roleId == null) {\n\t\t\tthrow new UacBizException(ErrorCodeEnum.UAC10012001);\n\t\t}\n\t\tUacRoleMenu roleMenu = new UacRoleMenu();\n\t\troleMenu.setRoleId(roleId);\n\t\treturn uacRoleMenuMapper.select(roleMenu);\n\t}\n\n\t@Override","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/paascloud/paascloud-master/blob/781281a9503332ed3cef44ea618349d14230a127/paascloud-provider/paascloud-provider-uac/src/main/java/com/paascloud/provider/service/impl/UacRoleMenuServiceImpl.java#L21-L57","documentation":"UacBizException UAC10012001 ('角色ID不能为空') thrown by UacRoleMenuServiceImpl.deleteByRoleId when roleId is null. Deleting role-menu bindings is keyed by roleId, so a null ID cannot identify rows and is rejected before the mapper delete runs.","triggerScenarios":"Calling uacRoleMenuService.deleteByRoleId(null), typically from a role-update flow that first unbinds old menus but received no roleId (e.g. new role creation path mistakenly routed here).","commonSituations":"Role-edit page where a role was not yet saved; a copy-pasted unbind call in a create flow; deserialized DTO with missing roleId field.","solutions":["Ensure a valid roleId is loaded before the delete call","Skip deleteByRoleId when creating a brand-new role (nothing to delete)","Validate roleId in the controller/service caller before delegating"],"exampleFix":"// before\nuacRoleMenuService.deleteByRoleId(role.getId());\nuacRoleMenuService.insert(role.getId(), menuIds);\n// after\nif (PublicUtil.isNotEmpty(role.getId())) {\n    uacRoleMenuService.deleteByRoleId(role.getId());\n}\nuacRoleMenuService.insert(role.getId(), menuIds);","handlingStrategy":"validation","validationCode":"if (roleId == null) {\n    return; // nothing to unbind for an unsaved role\n}","typeGuard":"boolean hasRole(Long roleId) { return roleId != null && roleId > 0; }","tryCatchPattern":"try {\n    uacRoleMenuService.deleteByRoleId(roleId);\n} catch (UacBizException e) {\n    if (ErrorCodeEnum.UAC10012001.getCode().equals(e.getCode())) {\n        logger.warn(\"deleteByRoleId called with null roleId\");\n        return;\n    }\n    throw e;\n}","preventionTips":["Skip unbind steps when creating new roles","Validate path/request variables before service calls","Keep unbind+rebind logic in one transactional method with a shared roleId check"],"tags":["java","null-check","validation","uac"],"backgroundTag":"null-argument","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"}