accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dlmar...@apache.org
Subject [1/2] accumulo git commit: ACCUMULO-4344: PortRange.parse with throw an error instead of fixing an invalid range
Date Tue, 14 Jun 2016 18:21:37 GMT
Repository: accumulo
Updated Branches:
  refs/heads/master c521cf810 -> 2b5b54bec


ACCUMULO-4344: PortRange.parse with throw an error instead of fixing an invalid range


Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo
Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/08d279f5
Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/08d279f5
Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/08d279f5

Branch: refs/heads/master
Commit: 08d279f530920afecffbaee816cbac470074f561
Parents: 7f8f66d
Author: Dave Marion <dlmarion@apache.org>
Authored: Tue Jun 14 14:20:21 2016 -0400
Committer: Dave Marion <dlmarion@apache.org>
Committed: Tue Jun 14 14:20:21 2016 -0400

----------------------------------------------------------------------
 .../java/org/apache/accumulo/core/conf/PropertyType.java | 11 ++++-------
 .../accumulo/core/conf/AccumuloConfigurationTest.java    |  4 ++--
 2 files changed, 6 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/accumulo/blob/08d279f5/core/src/main/java/org/apache/accumulo/core/conf/PropertyType.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/conf/PropertyType.java b/core/src/main/java/org/apache/accumulo/core/conf/PropertyType.java
index f08ab5b..6733fc6 100644
--- a/core/src/main/java/org/apache/accumulo/core/conf/PropertyType.java
+++ b/core/src/main/java/org/apache/accumulo/core/conf/PropertyType.java
@@ -25,6 +25,7 @@ import java.util.regex.Pattern;
 
 import org.apache.accumulo.core.Constants;
 import org.apache.accumulo.core.util.Pair;
+import org.apache.commons.lang.math.IntRange;
 import org.apache.hadoop.fs.Path;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -270,6 +271,7 @@ public enum PropertyType {
   public static class PortRange extends Matches {
 
     private static final Logger log = LoggerFactory.getLogger(PortRange.class);
+    private static final IntRange VALID_RANGE = new IntRange(1024, 65535);
 
     public PortRange(final String pattern) {
       super(pattern);
@@ -293,14 +295,9 @@ public enum PropertyType {
       int idx = portRange.indexOf('-');
       if (idx != -1) {
         int low = Integer.parseInt(portRange.substring(0, idx));
-        if (low < 1024) {
-          log.error("Invalid port number for low end of the range, using 1024");
-          low = 1024;
-        }
         int high = Integer.parseInt(portRange.substring(idx + 1));
-        if (high > 65535) {
-          log.error("Invalid port number for high end of the range, using 65535");
-          high = 65535;
+        if (!VALID_RANGE.containsInteger(low) || !VALID_RANGE.containsInteger(high) || !(low
<= high)) {
+          throw new IllegalArgumentException("Invalid port range specified, only 1024 to
65535 supported.");
         }
         return new Pair<Integer,Integer>(low, high);
       }

http://git-wip-us.apache.org/repos/asf/accumulo/blob/08d279f5/core/src/test/java/org/apache/accumulo/core/conf/AccumuloConfigurationTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/accumulo/core/conf/AccumuloConfigurationTest.java
b/core/src/test/java/org/apache/accumulo/core/conf/AccumuloConfigurationTest.java
index 61186bd..f12ba63 100644
--- a/core/src/test/java/org/apache/accumulo/core/conf/AccumuloConfigurationTest.java
+++ b/core/src/test/java/org/apache/accumulo/core/conf/AccumuloConfigurationTest.java
@@ -115,7 +115,7 @@ public class AccumuloConfigurationTest {
     assertEquals(9999, ports[2]);
   }
 
-  @Test
+  @Test(expected = IllegalArgumentException.class)
   public void testGetPortRangeInvalidLow() {
     AccumuloConfiguration c = AccumuloConfiguration.getDefaultConfiguration();
     ConfigurationCopy cc = new ConfigurationCopy(c);
@@ -127,7 +127,7 @@ public class AccumuloConfigurationTest {
     assertEquals(1026, ports[2]);
   }
 
-  @Test
+  @Test(expected = IllegalArgumentException.class)
   public void testGetPortRangeInvalidHigh() {
     AccumuloConfiguration c = AccumuloConfiguration.getDefaultConfiguration();
     ConfigurationCopy cc = new ConfigurationCopy(c);


Mime
View raw message