From 8a35e8b2f83099ec7536c30633663b43933d6c43 Mon Sep 17 00:00:00 2001 From: Wenjun Ruan Date: Mon, 19 Feb 2024 11:12:22 +0800 Subject: [PATCH] Fix switch task will throw exception when there is not parameters (#15594) --- .../server/master/utils/SwitchTaskUtils.java | 2 +- .../server/master/utils/SwitchTaskUtilsTest.java | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/utils/SwitchTaskUtils.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/utils/SwitchTaskUtils.java index f4ebd0c60c..40686474a4 100644 --- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/utils/SwitchTaskUtils.java +++ b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/utils/SwitchTaskUtils.java @@ -66,7 +66,7 @@ public class SwitchTaskUtils { Map varParams) { String content = condition.replaceAll("'", "\""); if (MapUtils.isEmpty(globalParams) && MapUtils.isEmpty(varParams)) { - throw new IllegalArgumentException("globalParams and varParams are both empty, please check it."); + return content; } Map params = Maps.newHashMap(); if (MapUtils.isNotEmpty(globalParams)) { diff --git a/dolphinscheduler-master/src/test/java/org/apache/dolphinscheduler/server/master/utils/SwitchTaskUtilsTest.java b/dolphinscheduler-master/src/test/java/org/apache/dolphinscheduler/server/master/utils/SwitchTaskUtilsTest.java index 18e97f8e80..e0654882ec 100644 --- a/dolphinscheduler-master/src/test/java/org/apache/dolphinscheduler/server/master/utils/SwitchTaskUtilsTest.java +++ b/dolphinscheduler-master/src/test/java/org/apache/dolphinscheduler/server/master/utils/SwitchTaskUtilsTest.java @@ -34,9 +34,8 @@ public class SwitchTaskUtilsTest { String content = "${test}==1"; Map globalParams = new HashMap<>(); Map varParams = new HashMap<>(); - Assertions.assertThrowsExactly(IllegalArgumentException.class, () -> { - SwitchTaskUtils.generateContentWithTaskParams(content, globalParams, varParams); - }); + Assertions.assertDoesNotThrow( + () -> SwitchTaskUtils.generateContentWithTaskParams(content, globalParams, varParams)); globalParams.put("test", new Property("test", Direct.IN, DataType.INTEGER, "1")); String result = SwitchTaskUtils.generateContentWithTaskParams(content, globalParams, varParams);