vkozhukhova commented on a change in pull request #8591:
URL: https://github.com/apache/ignite/pull/8591#discussion_r548441385



##########
File path: 
modules/core/src/main/java/org/apache/ignite/internal/util/HostAndPortRange.java
##########
@@ -53,60 +55,99 @@ public static HostAndPortRange parse(String addrStr, int 
dfltPortFrom, int dfltP
 
         String host;
 
+        String portStr;
         int portFrom;
         int portTo;
 
         if (F.isEmpty(addrStr))
             throw createParseError(addrStr, errMsgPrefix, "Address is empty");
 
-        final int colIdx = addrStr.indexOf(':');
-
-        if (colIdx > 0) {
-            String portFromStr;
-            String portToStr;
+        if (addrStr.charAt(0) == '[') { // IPv6 with port(s)
+            int hostEndIdx = addrStr.indexOf(']');
+            if (hostEndIdx == -1) {
+                throw createParseError(addrStr, errMsgPrefix, "IPv6 is 
incorrect");
+            }
+            host = addrStr.substring(1, hostEndIdx);
+            if (hostEndIdx == addrStr.length() - 1) { // no port specified, 
using default
+                portFrom = dfltPortFrom;
+                portTo = dfltPortTo;
+            } else { // port specified
+                portStr = addrStr.substring(hostEndIdx + 2);
+
+                int[] ports = verifyPortStr(addrStr, errMsgPrefix, portStr);
+                portFrom = ports[0];
+                portTo = ports[1];
+            }
+        } else { //IPv4 || IPv6 without port || empty host
+            final int colIdx = addrStr.lastIndexOf(':');
+            if (colIdx > 0) {
+                if (addrStr.substring(0, colIdx).contains(":")) { // IPv6 
without [] and port
+                    try {
+                        Inet6Address.getByName(addrStr);
+                        host = addrStr;
+                        portFrom = dfltPortFrom;
+                        portTo = dfltPortTo;
+                    }
+                    catch (UnknownHostException e) {
+                        throw createParseError(addrStr, errMsgPrefix, "IPv6 is 
incorrect");

Review comment:
       Overloaded `createParseError` method to pass cause.




----------------------------------------------------------------
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


Reply via email to