You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by se...@apache.org on 2020/06/23 20:41:07 UTC

[commons-net] branch master updated: Extract String into constant

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

sebb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-net.git


The following commit(s) were added to refs/heads/master by this push:
     new e6cb31f  Extract String into constant
e6cb31f is described below

commit e6cb31ffa8f2bfe0f93f1d27989df9c36808bfe6
Author: Sebb <se...@apache.org>
AuthorDate: Tue Jun 23 21:40:58 2020 +0100

    Extract String into constant
---
 src/main/java/org/apache/commons/net/util/SubnetUtils.java | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/src/main/java/org/apache/commons/net/util/SubnetUtils.java b/src/main/java/org/apache/commons/net/util/SubnetUtils.java
index 4aa38f3..9a22ade 100644
--- a/src/main/java/org/apache/commons/net/util/SubnetUtils.java
+++ b/src/main/java/org/apache/commons/net/util/SubnetUtils.java
@@ -32,6 +32,8 @@ public class SubnetUtils {
     private static final Pattern cidrPattern = Pattern.compile(SLASH_FORMAT);
     private static final int NBITS = 32;
 
+    private static final String PARSE_FAIL = "Could not parse [%s]";
+
     private final int netmask;
     private final int address;
     private final int network;
@@ -72,7 +74,7 @@ public class SubnetUtils {
           /* Calculate broadcast address */
           this.broadcast = network | ~(netmask);
       } else {
-          throw new IllegalArgumentException("Could not parse [" + cidrNotation + "]");
+          throw new IllegalArgumentException(String.format(PARSE_FAIL, cidrNotation));
       }
     }
 
@@ -88,7 +90,7 @@ public class SubnetUtils {
         this.netmask = toInteger(mask);
 
         if ((this.netmask & -this.netmask) - 1 != ~this.netmask) {
-            throw new IllegalArgumentException("Could not parse [" + mask + "]");
+            throw new IllegalArgumentException(String.format(PARSE_FAIL, mask));
         }
 
         /* Calculate base network address */
@@ -303,7 +305,7 @@ public class SubnetUtils {
         if (matcher.matches()) {
             return matchAddress(matcher);
         } else {
-            throw new IllegalArgumentException("Could not parse [" + address + "]");
+            throw new IllegalArgumentException(String.format(PARSE_FAIL, address));
         }
     }