瀏覽代碼

HDFS-17449. Fix ill-formed decommission host name and port pair triggers IndexOutOfBound error (#6691). Contributed by ConfX

Signed-off-by: Ayush Saxena <ayushsaxena@apache.org>
ConfX 1 年之前
父節點
當前提交
73e6931ed0

+ 4 - 0
hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/util/HostsFileWriter.java

@@ -106,6 +106,10 @@ public class HostsFileWriter {
         for (String hostNameAndPort : decommissionHostNameAndPorts) {
           DatanodeAdminProperties dn = new DatanodeAdminProperties();
           String[] hostAndPort = hostNameAndPort.split(":");
+          if (hostAndPort.length != 2) {
+            throw new IllegalArgumentException("The decommision host name and port format is "
+                + "invalid. The format should be in <host>:<port>, not " + hostNameAndPort);
+          }
           dn.setHostName(hostAndPort[0]);
           dn.setPort(Integer.parseInt(hostAndPort[1]));
           dn.setAdminState(AdminStates.DECOMMISSIONED);