From 4868051399bc70b95e1fea0a4b85f5166ef26318 Mon Sep 17 00:00:00 2001 From: luoweijian <1329394916@qq.com> Date: Tue, 4 Aug 2026 10:12:20 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20validateHierarchy=20=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=20parentType=20null=20=E5=AE=88=E5=8D=AB=EF=BC=8C=E9=98=B2?= =?UTF-8?q?=E6=AD=A2=20switch=20NPE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Spec review 发现:MenuType.fromCode() 对未知 DB 值返回 null 时,switch 表达式会抛 NPE 500, 改为提前抛 BusinessErrorException 并附带 menuType 值,便于排查脏数据。 --- .../java/com/crm/auth/service/impl/ResourceServiceImpl.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/crm-auth/src/main/java/com/crm/auth/service/impl/ResourceServiceImpl.java b/crm-auth/src/main/java/com/crm/auth/service/impl/ResourceServiceImpl.java index 041c789..f39410c 100644 --- a/crm-auth/src/main/java/com/crm/auth/service/impl/ResourceServiceImpl.java +++ b/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()); } MenuType parentType = MenuType.fromCode(parent.getMenuType()); + if (parentType == null) { + throw new BusinessErrorException(CODE_RESOURCE_INVALID, + "父节点类型未知:menuType=" + parent.getMenuType()); + } if (!MenuType.isLegalChild(parentType, childType)) { String msg = switch (parentType) {