HADOOP-15755. StringUtils#createStartupShutdownMessage throws NPE when args is null. Contributed by Lokesh Jain and Dinesh Chitlangia

(cherry picked from commit e71f61ecb8)

Conflicts:
	hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestStringUtils.java
This commit is contained in:
Jason Lowe 2018-09-18 15:55:09 -05:00
parent 3d77094cf2
commit 610b00bdf4
2 changed files with 10 additions and 1 deletions

View File

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

View File

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