You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dolphinscheduler.apache.org by ki...@apache.org on 2020/11/24 10:32:59 UTC

[incubator-dolphinscheduler] branch dev updated: fix replaceNRTtoUnderline NullPointerException #4098 (#4100)

This is an automated email from the ASF dual-hosted git repository.

kirs pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/incubator-dolphinscheduler.git


The following commit(s) were added to refs/heads/dev by this push:
     new 8f5da09  fix replaceNRTtoUnderline NullPointerException #4098 (#4100)
8f5da09 is described below

commit 8f5da09d3e078ca8857f033ed440052d26e3e2a7
Author: felix.wang <59...@users.noreply.github.com>
AuthorDate: Tue Nov 24 18:32:50 2020 +0800

    fix replaceNRTtoUnderline NullPointerException #4098 (#4100)
    
    * fix replaceNRTtoUnderline NullPointerException
    
    * add  unit Test
---
 .../dolphinscheduler/common/utils/StringUtils.java       |  6 +++++-
 .../dolphinscheduler/common/utils/StringUtilsTest.java   | 16 ++++++++++++++++
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/StringUtils.java b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/StringUtils.java
index 4f4f127..bedfa85 100644
--- a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/StringUtils.java
+++ b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/StringUtils.java
@@ -45,6 +45,10 @@ public class StringUtils {
     }
 
     public static String replaceNRTtoUnderline(String src) {
-        return src.replaceAll("[\n|\r|\t]", "_");
+        if (isBlank(src)) {
+            return src;
+        } else {
+            return src.replaceAll("[\n|\r|\t]", "_");
+        }
     }
 }
diff --git a/dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/StringUtilsTest.java b/dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/StringUtilsTest.java
index eca22de..f67e89e 100644
--- a/dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/StringUtilsTest.java
+++ b/dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/StringUtilsTest.java
@@ -14,6 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
 package org.apache.dolphinscheduler.common.utils;
 
 import org.junit.Assert;
@@ -61,4 +62,19 @@ public class StringUtilsTest {
         b = StringUtils.isNotBlank("test");
         Assert.assertTrue(b);
     }
+
+    @Test
+    public void testreplaceNRTtoUnderline() {
+        String result1 = StringUtils.replaceNRTtoUnderline("abc\n");
+        Assert.assertEquals("abc_", result1);
+
+        String result2 = StringUtils.replaceNRTtoUnderline("abc\r");
+        Assert.assertEquals("abc_", result2);
+
+        String result3 = StringUtils.replaceNRTtoUnderline("abc\t");
+        Assert.assertEquals("abc_", result3);
+
+        String result4 = StringUtils.replaceNRTtoUnderline(null);
+        Assert.assertNull(result4);
+    }
 }