diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt index 99320cbfb28..522ec47f704 100644 --- a/hadoop-common-project/hadoop-common/CHANGES.txt +++ b/hadoop-common-project/hadoop-common/CHANGES.txt @@ -602,6 +602,9 @@ Release 2.7.0 - UNRELEASED HADOOP-9869. Configuration.getSocketAddr()/getEnum() should use getTrimmed(). (Tsuyoshi Ozawa via aajisaka) + HADOOP-11589. NetUtils.createSocketAddr should trim the input URI. + (Rakesh R via ozawa) + OPTIMIZATIONS HADOOP-11323. WritableComparator#compare keeps reference to byte array. diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/net/NetUtils.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/net/NetUtils.java index ef1092bb2f7..e475149aaa4 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/net/NetUtils.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/net/NetUtils.java @@ -189,6 +189,7 @@ public class NetUtils { throw new IllegalArgumentException("Target address cannot be null." + helpText); } + target = target.trim(); boolean hasScheme = target.contains("://"); URI uri = null; try { diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/net/TestNetUtils.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/net/TestNetUtils.java index 319e8a9f2a4..a12054b1b31 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/net/TestNetUtils.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/net/TestNetUtils.java @@ -643,6 +643,17 @@ public class TestNetUtils { assertNotNull(NetUtils.getHostNameOfIP("127.0.0.1:1")); } + @Test + public void testTrimCreateSocketAddress() { + Configuration conf = new Configuration(); + NetUtils.addStaticResolution("host", "127.0.0.1"); + final String defaultAddr = "host:1 "; + + InetSocketAddress addr = NetUtils.createSocketAddr(defaultAddr); + conf.setSocketAddr("myAddress", addr); + assertEquals(defaultAddr.trim(), NetUtils.getHostPortString(addr)); + } + private void assertBetterArrayEquals(T[] expect, T[]got) { String expectStr = StringUtils.join(expect, ", "); String gotStr = StringUtils.join(got, ", ");