diff --git a/backend/src/main/java/io/metersphere/service/NodeTreeService.java b/backend/src/main/java/io/metersphere/service/NodeTreeService.java index cd2ecc2737..d9ea693571 100644 --- a/backend/src/main/java/io/metersphere/service/NodeTreeService.java +++ b/backend/src/main/java/io/metersphere/service/NodeTreeService.java @@ -83,18 +83,18 @@ public class NodeTreeService { return nodeTree; } - List children = Optional.ofNullable(nodeTree.getChildren()).orElse(new ArrayList<>()); + List children = new ArrayList<>(); lowerNodes.forEach(node -> { if (node.getParentId() != null && node.getParentId().equals(rootNode.getId())) { children.add(buildNodeTree(nodeLevelMap, node, countMap)); - if (countMap != null) { - Integer childrenCount = children.stream().map(TreeNodeDTO::getCaseNum).reduce(Integer::sum).get(); - nodeTree.setCaseNum(nodeTree.getCaseNum() + childrenCount); - } nodeTree.setChildren(children); } }); + if (countMap != null && CollectionUtils.isNotEmpty(children)) { + Integer childrenCount = children.stream().map(TreeNodeDTO::getCaseNum).reduce(Integer::sum).get(); + nodeTree.setCaseNum(nodeTree.getCaseNum() + childrenCount); + } return nodeTree; }