Doing an explicit null check in PassivePorts (FTPSERVER-415)
authorNiklas Gustavsson <ngn@apache.org>
Wed, 1 Jun 2011 13:07:00 +0000 (13:07 +0000)
committerNiklas Gustavsson <ngn@apache.org>
Wed, 1 Jun 2011 13:07:00 +0000 (13:07 +0000)
git-svn-id: https://svn.apache.org/repos/asf/mina/ftpserver/trunk@1130138 13f79535-47bb-0310-9956-ffa450edef68

core/src/main/java/org/apache/ftpserver/impl/PassivePorts.java
core/src/test/java/org/apache/ftpserver/impl/PassivePortsTest.java

index f539540..19585ec 100644 (file)
@@ -158,11 +158,11 @@ public class PassivePorts {
     }
 
     public PassivePorts(final int[] passivePorts, boolean checkIfBound) {
-        if (passivePorts != null) {
-            this.passivePorts = passivePorts.clone();
-        } else {
-            this.passivePorts = null;
-        }
+       if(passivePorts == null) {
+               throw new NullPointerException("passivePorts can not be null");
+       }
+       
+        this.passivePorts = passivePorts.clone();
 
         reservedPorts = new boolean[passivePorts.length];
         this.checkIfBound = checkIfBound;
index 57021de..1167e20 100644 (file)
@@ -203,4 +203,12 @@ public class PassivePortsTest extends TestCase {
         assertEquals(-1, ports.reserveNextPort());
     }
 
+    public void testNullPorts() {
+       try {
+               new PassivePorts((int[])null, false);
+               fail("Must throw NPE");
+       } catch(NullPointerException e) {
+               // ok
+       }
+    }
 }