Copilot commented on code in PR #18162:
URL: https://github.com/apache/iotdb/pull/18162#discussion_r3575444756
##########
iotdb-client/service-rpc/src/main/java/org/apache/iotdb/rpc/UrlUtils.java:
##########
@@ -21,33 +21,95 @@
import org.apache.iotdb.common.rpc.thrift.TEndPoint;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+
/** The UrlUtils */
public class UrlUtils {
private static final String PORT_SEPARATOR = ":";
- private static final String ABB_COLON = "[";
+ private static final String IPV6_BEGIN_MARK = "[";
+ private static final String IPV6_END_MARK = "]";
private UrlUtils() {}
/**
* Parse TEndPoint from a given TEndPointUrl
* example:[D80:0000:0000:0000:ABAA:0000:00C2:0002]:22227
*
- * @param endPointUrl ip:port
- * @return TEndPoint null if parse error
+ * @param endPointUrl host:port or [ipv6]:port
+ * @return parsed TEndPoint
+ * @throws NumberFormatException if the bracketed endpoint format is invalid
or the port is not a
+ * number
*/
public static TEndPoint parseTEndPointIpv4AndIpv6Url(String endPointUrl) {
TEndPoint endPoint = new TEndPoint();
+ if (endPointUrl.startsWith(IPV6_BEGIN_MARK)) {
+ int endIndex = endPointUrl.indexOf(IPV6_END_MARK);
+ if (endIndex <= 1
Review Comment:
UrlUtils.parseTEndPointIpv4AndIpv6Url() currently returns an empty/default
TEndPoint when the input has no port separator (e.g., "localhost"), even though
the method Javadoc says the format is host:port or [ipv6]:port. This can
silently propagate a null/empty host and later cause confusing failures
(including NPEs in convertTEndPointIpv4AndIpv6Url when formatting such an
endpoint). Consider validating that both host and port are present for the
non-bracketed path, and throw NumberFormatException consistently for
missing/empty host/port.
--
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]