diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/util/Addressing.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/util/Addressing.java index 46042c2500b..891ad355a35 100644 --- a/hbase-common/src/main/java/org/apache/hadoop/hbase/util/Addressing.java +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/util/Addressing.java @@ -152,6 +152,21 @@ public class Addressing { return local; } + /** + * Given an InetSocketAddress object returns a String represent of it. + * This is a util method for Java 17. The toString() function of InetSocketAddress + * will flag the unresolved address with a substring in the string, which will result + * in unexpected problem. We should use this util function to get the string when we + * not sure whether the input address is resolved or not. + * @param address address to convert to a "host:port" String. + * @return the String represent of the given address, like "foo:1234". + */ + public static String inetSocketAddress2String(InetSocketAddress address) { + return address.isUnresolved() ? + address.toString().replace("/", "") : + address.toString(); + } + /** * Interface for AddressSelectionCondition to check if address is acceptable */ diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/tool/CanaryTool.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/tool/CanaryTool.java index df48083cf01..4f6638e9c43 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/tool/CanaryTool.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/tool/CanaryTool.java @@ -20,6 +20,7 @@ package org.apache.hadoop.hbase.tool; import static org.apache.hadoop.hbase.HConstants.DEFAULT_ZOOKEEPER_ZNODE_PARENT; import static org.apache.hadoop.hbase.HConstants.ZOOKEEPER_ZNODE_PARENT; +import static org.apache.hadoop.hbase.util.Addressing.inetSocketAddress2String; import java.io.Closeable; import java.io.IOException; import java.net.BindException; @@ -1707,7 +1708,7 @@ public class CanaryTool implements Tool, Canary { new ConnectStringParser(ZKConfig.getZKQuorumServersString(configuration)); hosts = Lists.newArrayList(); for (InetSocketAddress server : parser.getServerAddresses()) { - hosts.add(server.toString()); + hosts.add(inetSocketAddress2String(server)); } if (allowedFailures > (hosts.size() - 1) / 2) { LOG.warn(