Skip to content

Commit e1ca056

Browse files
authored
HBASE-26410 Fix HBase TestCanaryTool for Java17 (#3809)
Signed-off-by: Duo Zhang <[email protected]>
1 parent 407a5bd commit e1ca056

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

hbase-common/src/main/java/org/apache/hadoop/hbase/util/Addressing.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,21 @@ public static boolean isLocalAddress(InetAddress addr) {
152152
return local;
153153
}
154154

155+
/**
156+
* Given an InetSocketAddress object returns a String represent of it.
157+
* This is a util method for Java 17. The toString() function of InetSocketAddress
158+
* will flag the unresolved address with a substring in the string, which will result
159+
* in unexpected problem. We should use this util function to get the string when we
160+
* not sure whether the input address is resolved or not.
161+
* @param address address to convert to a "host:port" String.
162+
* @return the String represent of the given address, like "foo:1234".
163+
*/
164+
public static String inetSocketAddress2String(InetSocketAddress address) {
165+
return address.isUnresolved() ?
166+
address.toString().replace("/<unresolved>", "") :
167+
address.toString();
168+
}
169+
155170
/**
156171
* Interface for AddressSelectionCondition to check if address is acceptable
157172
*/

hbase-server/src/main/java/org/apache/hadoop/hbase/tool/CanaryTool.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import static org.apache.hadoop.hbase.HConstants.DEFAULT_ZOOKEEPER_ZNODE_PARENT;
2222
import static org.apache.hadoop.hbase.HConstants.ZOOKEEPER_ZNODE_PARENT;
23+
import static org.apache.hadoop.hbase.util.Addressing.inetSocketAddress2String;
2324
import java.io.Closeable;
2425
import java.io.IOException;
2526
import java.net.BindException;
@@ -1707,7 +1708,7 @@ protected ZookeeperMonitor(Connection connection, String[] monitorTargets, boole
17071708
new ConnectStringParser(ZKConfig.getZKQuorumServersString(configuration));
17081709
hosts = Lists.newArrayList();
17091710
for (InetSocketAddress server : parser.getServerAddresses()) {
1710-
hosts.add(server.toString());
1711+
hosts.add(inetSocketAddress2String(server));
17111712
}
17121713
if (allowedFailures > (hosts.size() - 1) / 2) {
17131714
LOG.warn(

0 commit comments

Comments
 (0)