commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r1196001 - in /commons/proper/net/trunk/src: changes/changes.xml main/java/org/apache/commons/net/util/SubnetUtils.java test/java/org/apache/commons/net/SubnetUtilsTest.java
Date Tue, 01 Nov 2011 14:13:55 GMT
Author: sebb
Date: Tue Nov  1 14:13:54 2011
New Revision: 1196001

URL: http://svn.apache.org/viewvc?rev=1196001&view=rev
Log:
NET-428 SubnetUtils throws ArrayIndexOutOfBoundsException for new SubnetUtils( "1.2.3.4/32"
).getInfo().getAllAddresses()

Modified:
    commons/proper/net/trunk/src/changes/changes.xml
    commons/proper/net/trunk/src/main/java/org/apache/commons/net/util/SubnetUtils.java
    commons/proper/net/trunk/src/test/java/org/apache/commons/net/SubnetUtilsTest.java

Modified: commons/proper/net/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/net/trunk/src/changes/changes.xml?rev=1196001&r1=1196000&r2=1196001&view=diff
==============================================================================
--- commons/proper/net/trunk/src/changes/changes.xml (original)
+++ commons/proper/net/trunk/src/changes/changes.xml Tue Nov  1 14:13:54 2011
@@ -59,6 +59,9 @@ The <action> type attribute can be add,u
         <release version="3.0.2-SNAPSHOT" date="TBA" description="
 TBA
         ">
+            <action issue="NET-428" dev="sebb" type="fix">
+            SubnetUtils throws ArrayIndexOutOfBoundsException for new SubnetUtils( "1.2.3.4/32"
).getInfo().getAllAddresses()
+            </action>
             <action issue="NET-421" dev="sebb" type="fix" due-to="Oliver Saggau">
             Problem connecting to TLS/SSL SMTP server using explicit mode.
             </action>

Modified: commons/proper/net/trunk/src/main/java/org/apache/commons/net/util/SubnetUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/net/trunk/src/main/java/org/apache/commons/net/util/SubnetUtils.java?rev=1196001&r1=1196000&r2=1196001&view=diff
==============================================================================
--- commons/proper/net/trunk/src/main/java/org/apache/commons/net/util/SubnetUtils.java (original)
+++ commons/proper/net/trunk/src/main/java/org/apache/commons/net/util/SubnetUtils.java Tue
Nov  1 14:13:54 2011
@@ -161,7 +161,11 @@ public class SubnetUtils {
         }
 
         public String[] getAllAddresses() {
-            String[] addresses = new String[getAddressCount()];
+            int ct = getAddressCount();
+            String[] addresses = new String[ct];
+            if (ct == 0) {
+                return addresses;
+            }
             for (int add = low(), j=0; add <= high(); ++add, ++j) {
                 addresses[j] = format(toArray(add));
             }

Modified: commons/proper/net/trunk/src/test/java/org/apache/commons/net/SubnetUtilsTest.java
URL: http://svn.apache.org/viewvc/commons/proper/net/trunk/src/test/java/org/apache/commons/net/SubnetUtilsTest.java?rev=1196001&r1=1196000&r2=1196001&view=diff
==============================================================================
--- commons/proper/net/trunk/src/test/java/org/apache/commons/net/SubnetUtilsTest.java (original)
+++ commons/proper/net/trunk/src/test/java/org/apache/commons/net/SubnetUtilsTest.java Tue
Nov  1 14:13:54 2011
@@ -290,4 +290,20 @@ public class SubnetUtilsTest extends Tes
         } catch (IllegalArgumentException expected) {
         }
     }
+
+    public void testNET428_31() throws Exception {
+        final SubnetUtils subnetUtils = new SubnetUtils("1.2.3.4/31");
+        assertEquals(0,subnetUtils.getInfo().getAddressCount());
+        String[] address = subnetUtils.getInfo().getAllAddresses();
+        assertNotNull(address);
+        assertEquals(0,address.length);
+    }
+
+    public void testNET428_32() throws Exception {
+        final SubnetUtils subnetUtils = new SubnetUtils("1.2.3.4/32");
+        assertEquals(0,subnetUtils.getInfo().getAddressCount());
+        String[] address = subnetUtils.getInfo().getAllAddresses();
+        assertNotNull(address);
+        assertEquals(0,address.length);
+    }
 }



Mime
View raw message