Browse Source

fix: validateHierarchy 增加 parentType null 守卫,防止 switch NPE

Spec review 发现:MenuType.fromCode() 对未知 DB 值返回 null 时,switch 表达式会抛 NPE 500,
改为提前抛 BusinessErrorException 并附带 menuType 值,便于排查脏数据。
master
luoweijian 1 month ago
parent
commit
4868051399
  1. 4
      crm-auth/src/main/java/com/crm/auth/service/impl/ResourceServiceImpl.java

4
crm-auth/src/main/java/com/crm/auth/service/impl/ResourceServiceImpl.java

@ -178,6 +178,10 @@ public class ResourceServiceImpl implements IResourceService {
throw new BusinessErrorException(CODE_RESOURCE_INVALID, "父节点不存在:parentId=" + node.getParentId()); throw new BusinessErrorException(CODE_RESOURCE_INVALID, "父节点不存在:parentId=" + node.getParentId());
} }
MenuType parentType = MenuType.fromCode(parent.getMenuType()); MenuType parentType = MenuType.fromCode(parent.getMenuType());
if (parentType == null) {
throw new BusinessErrorException(CODE_RESOURCE_INVALID,
"父节点类型未知:menuType=" + parent.getMenuType());
}
if (!MenuType.isLegalChild(parentType, childType)) { if (!MenuType.isLegalChild(parentType, childType)) {
String msg = switch (parentType) { String msg = switch (parentType) {

Loading…
Cancel
Save