Doing an explicit null check in PassivePorts (FTPSERVER-415) git-svn-id: https://svn.apache.org/repos/asf/mina/ftpserver/trunk@1130138 13f79535-47bb-0310-9956-ffa450edef68
Project: http://git-wip-us.apache.org/repos/asf/mina-ftpserver/repo Commit: http://git-wip-us.apache.org/repos/asf/mina-ftpserver/commit/e09a4321 Tree: http://git-wip-us.apache.org/repos/asf/mina-ftpserver/tree/e09a4321 Diff: http://git-wip-us.apache.org/repos/asf/mina-ftpserver/diff/e09a4321 Branch: refs/heads/trunk Commit: e09a4321596953185e980396a5353e1631497b43 Parents: 75f7e60 Author: Niklas Gustavsson <[email protected]> Authored: Wed Jun 1 13:07:00 2011 +0000 Committer: Niklas Gustavsson <[email protected]> Committed: Wed Jun 1 13:07:00 2011 +0000 ---------------------------------------------------------------------- .../main/java/org/apache/ftpserver/impl/PassivePorts.java | 10 +++++----- .../java/org/apache/ftpserver/impl/PassivePortsTest.java | 8 ++++++++ 2 files changed, 13 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mina-ftpserver/blob/e09a4321/core/src/main/java/org/apache/ftpserver/impl/PassivePorts.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/ftpserver/impl/PassivePorts.java b/core/src/main/java/org/apache/ftpserver/impl/PassivePorts.java index f539540..19585ec 100644 --- a/core/src/main/java/org/apache/ftpserver/impl/PassivePorts.java +++ b/core/src/main/java/org/apache/ftpserver/impl/PassivePorts.java @@ -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; http://git-wip-us.apache.org/repos/asf/mina-ftpserver/blob/e09a4321/core/src/test/java/org/apache/ftpserver/impl/PassivePortsTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/ftpserver/impl/PassivePortsTest.java b/core/src/test/java/org/apache/ftpserver/impl/PassivePortsTest.java index 57021de..1167e20 100644 --- a/core/src/test/java/org/apache/ftpserver/impl/PassivePortsTest.java +++ b/core/src/test/java/org/apache/ftpserver/impl/PassivePortsTest.java @@ -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 + } + } }
