You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by li...@apache.org on 2020/04/02 13:23:21 UTC

[dubbo] branch master updated: polish NetUtils#matchIpRange (#5773)

This is an automated email from the ASF dual-hosted git repository.

liujun pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/dubbo.git


The following commit(s) were added to refs/heads/master by this push:
     new d6672af  polish NetUtils#matchIpRange (#5773)
d6672af is described below

commit d6672afbee70a9fea98a876a225ccb7ea17e028a
Author: tangcent <sw...@foxmail.com>
AuthorDate: Thu Apr 2 21:23:04 2020 +0800

    polish NetUtils#matchIpRange (#5773)
---
 .../java/org/apache/dubbo/common/utils/NetUtils.java    | 17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)

diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/NetUtils.java b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/NetUtils.java
index f16dd06..5477bc6 100644
--- a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/NetUtils.java
+++ b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/NetUtils.java
@@ -100,7 +100,7 @@ public class NetUtils {
             return getAvailablePort();
         }
         for (int i = port; i < MAX_PORT; i++) {
-            try (ServerSocket ss = new ServerSocket(i)) {
+            try (ServerSocket ignored = new ServerSocket(i)) {
                 return i;
             } catch (IOException e) {
                 // continue
@@ -515,7 +515,7 @@ public class NetUtils {
         }
 
         InetAddress inetAddress = InetAddress.getByName(host);
-        boolean isIpv4 = isValidV4Address(inetAddress) ? true : false;
+        boolean isIpv4 = isValidV4Address(inetAddress);
         String[] hostAndPort = getPatternHostAndPort(pattern, isIpv4);
         if (hostAndPort[1] != null && !hostAndPort[1].equals(String.valueOf(port))) {
             return false;
@@ -531,25 +531,22 @@ public class NetUtils {
         checkHostPattern(pattern, mask, isIpv4);
 
         host = inetAddress.getHostAddress();
-
-        String[] ipAddress = host.split(splitCharacter);
         if (pattern.equals(host)) {
             return true;
         }
+
         // short name condition
         if (!ipPatternContainExpression(pattern)) {
             InetAddress patternAddress = InetAddress.getByName(pattern);
-            if (patternAddress.getHostAddress().equals(host)) {
-                return true;
-            } else {
-                return false;
+            return patternAddress.getHostAddress().equals(host);
             }
-        }
+
+        String[] ipAddress = host.split(splitCharacter);
         for (int i = 0; i < mask.length; i++) {
             if ("*".equals(mask[i]) || mask[i].equals(ipAddress[i])) {
                 continue;
             } else if (mask[i].contains("-")) {
-                String[] rangeNumStrs = mask[i].split("-");
+                String[] rangeNumStrs = StringUtils.split(mask[i], '-');
                 if (rangeNumStrs.length != 2) {
                     throw new IllegalArgumentException("There is wrong format of ip Address: " + mask[i]);
                 }