Copilot commented on code in PR #8669:
URL: https://github.com/apache/hadoop/pull/8669#discussion_r3755728581


##########
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/net/NetUtils.java:
##########
@@ -763,10 +766,29 @@ public static String getHostname() {
    * Compose a "host:port" string from the address.
    *
    * @param addr address.
-   * @return hort port string.
+   * @return host port string.
    */
   public static String getHostPortString(InetSocketAddress addr) {
-    return addr.getHostName() + ":" + addr.getPort();
+    return getHostPortString(addr.getHostName(), addr.getPort());
+  }
+
+  /**
+   * Compose a "host:port" string, bracketing IPv6 literals.
+   *
+   * @param host host name or IP address.
+   * @param port port number.
+   * @return host port string.
+   */
+  public static String getHostPortString(String host, int port) {
+    String normalizedHost = host;
+    if (normalizedHost != null && normalizedHost.startsWith("[")
+        && normalizedHost.endsWith("]")) {
+      normalizedHost = normalizedHost.substring(1, normalizedHost.length() - 
1);
+    }
+    if (normalizedHost != null && normalizedHost.contains(":")) {
+      return "[" + normalizedHost + "]:" + port;
+    }
+    return normalizedHost + ":" + port;

Review Comment:
   NetUtils.getHostPortString(host, port) now deliberately emits bracketed IPv6 
literals (e.g., "[::1]:123"), but NetUtils.getPortFromHostPortString still 
splits on ":" and rejects anything except exactly one colon. This makes the two 
helpers inconsistent and will fail for any caller that needs to extract the 
port from a bracketed IPv6 authority.
   
   Update getPortFromHostPortString() to accept both "<host>:<port>" and 
"[<ipv6>]:<port>" (and explicitly reject ambiguous unbracketed IPv6).



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to