From e71f61ecb87e04727a5a76e578a75714c9db6706 Mon Sep 17 00:00:00 2001 From: Jason Lowe Date: Tue, 18 Sep 2018 15:55:09 -0500 Subject: [PATCH] HADOOP-15755. StringUtils#createStartupShutdownMessage throws NPE when args is null. Contributed by Lokesh Jain and Dinesh Chitlangia --- .../main/java/org/apache/hadoop/util/StringUtils.java | 2 +- .../java/org/apache/hadoop/util/TestStringUtils.java | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/StringUtils.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/StringUtils.java index 3db805fa4f..f49698ca5a 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/StringUtils.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/StringUtils.java @@ -743,7 +743,7 @@ public static String createStartupShutdownMessage(String classname, return toStartupShutdownString("STARTUP_MSG: ", new String[] { "Starting " + classname, " host = " + hostname, - " args = " + Arrays.asList(args), + " args = " + (args != null ? Arrays.asList(args) : new ArrayList<>()), " version = " + VersionInfo.getVersion(), " classpath = " + System.getProperty("java.class.path"), " build = " + VersionInfo.getUrl() + " -r " diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestStringUtils.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestStringUtils.java index 3fdc1bb8f8..f05b589567 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestStringUtils.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestStringUtils.java @@ -503,6 +503,15 @@ public void testEscapeHTML() { escapedStr, StringUtils.escapeHTML(htmlStr)); } + @Test + public void testCreateStartupShutdownMessage() { + //pass null args and method must still return a string beginning with + // "STARTUP_MSG" + String msg = StringUtils.createStartupShutdownMessage( + this.getClass().getName(), "test.host", null); + assertTrue(msg.startsWith("STARTUP_MSG:")); + } + // Benchmark for StringUtils split public static void main(String []args) { final String TO_SPLIT = "foo,bar,baz,blah,blah";