diff --git a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/DateUtils.java b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/DateUtils.java index a5312995ac..c484dc0442 100644 --- a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/DateUtils.java +++ b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/DateUtils.java @@ -259,6 +259,9 @@ public class DateUtils { * @return format time */ public static String format2Duration(Date d1, Date d2) { + if (d1 == null || d2 == null) { + return null; + } return format2Duration(differMs(d1, d2)); } diff --git a/dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/DateUtilsTest.java b/dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/DateUtilsTest.java index 63f0be5906..4a88085d19 100644 --- a/dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/DateUtilsTest.java +++ b/dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/DateUtilsTest.java @@ -153,7 +153,7 @@ public class DateUtilsTest { @Test public void getCurrentTimeStamp() { - String timeStamp = DateUtils.getCurrentTimeStamp(); + String timeStamp = DateUtils.getCurrentTimeStamp(); Assert.assertNotNull(timeStamp); } @@ -196,4 +196,12 @@ public class DateUtilsTest { } + @Test + public void testNullDuration() { + // days hours minutes seconds + Date d1 = DateUtils.stringToDate("2020-01-20 11:00:00"); + Date d2 = null; + Assert.assertNull(DateUtils.format2Duration(d1, d2)); + } + }