kpatelatwork commented on a change in pull request #10530: URL: https://github.com/apache/kafka/pull/10530#discussion_r612545585
########## File path: connect/runtime/src/main/java/org/apache/kafka/connect/runtime/rest/RestServer.java ########## @@ -369,9 +370,31 @@ else if (serverConnector != null && serverConnector.getHost() != null && serverC else if (serverConnector != null && serverConnector.getPort() > 0) builder.port(serverConnector.getPort()); - log.info("Advertised URI: {}", builder.build()); + URI uri = builder.build(); + validateUriHost(uri); + log.info("Advertised URI: {}", uri); - return builder.build(); + return uri; + } + + /** + * Parses the uri and throws a more definitive error + * when the internal node to node communication can't happen due to an invalid host name. + */ + private void validateUriHost(URI uri) { + if (uri.getHost() == null) { + String host = Utils.getHost(uri.getAuthority()); Review comment: You are right, if the domain name is invalid then Uri parsing gives up and this is why authority will have the "host:port" pattern but the host and port will be null and thats why I am using Utils.getHost uses regex to parse this out of authority(not reinventing the wheel as the method was already there). The other alternative I had considered was "new URL(uri.toString()).getHost()" but in the future if java fixes the bug then it may also start returning null like URI. -- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org