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";