From f2eeba5c5bffbed7f3263208fa0170cc452a0237 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 (cherry picked from commit e71f61ecb87e04727a5a76e578a75714c9db6706) Conflicts: hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestStringUtils.java --- .../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 cda5ec794e2..05c8928df65 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 class StringUtils { 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 1f474f8c7f5..6b9a7d4d962 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 @@ -476,6 +476,15 @@ public class TestStringUtils extends UnitTestcaseTimeLimit { executorService.awaitTermination(50, TimeUnit.SECONDS); } + @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";