check for null protocol while validating ACL item

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

Branch: refs/heads/object_store
Commit: aa2fb311124599113ee73e00b583683976be615f
Parents: cc7e9ee
Author: Kishan Kavala <[email protected]>
Authored: Wed Jun 5 16:40:24 2013 +0530
Committer: Kishan Kavala <[email protected]>
Committed: Thu Jun 6 19:02:44 2013 +0530

----------------------------------------------------------------------
 .../network/vpc/NetworkACLServiceImpl.java      | 40 ++++++++++----------
 1 file changed, 21 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/aa2fb311/server/src/com/cloud/network/vpc/NetworkACLServiceImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/vpc/NetworkACLServiceImpl.java 
b/server/src/com/cloud/network/vpc/NetworkACLServiceImpl.java
index d6e86e2..4ad22d9 100644
--- a/server/src/com/cloud/network/vpc/NetworkACLServiceImpl.java
+++ b/server/src/com/cloud/network/vpc/NetworkACLServiceImpl.java
@@ -303,28 +303,30 @@ public class NetworkACLServiceImpl extends ManagerBase 
implements NetworkACLServ
         }
 
         //Validate Protocol
-        //Check if protocol is a number
-        if(StringUtils.isNumeric(protocol)){
-            int protoNumber = Integer.parseInt(protocol);
-            if(protoNumber < 0 || protoNumber > 255){
-                throw new InvalidParameterValueException("Invalid protocol 
number: " + protoNumber);
-            }
-        } else {
-            //Protocol is not number
-            //Check for valid protocol strings
-            String supportedProtocols = "tcp,udp,icmp,all";
-            if(!supportedProtocols.contains(protocol.toLowerCase())){
-                throw new InvalidParameterValueException("Invalid protocol: " 
+ protocol);
+        if(protocol != null){
+            //Check if protocol is a number
+            if(StringUtils.isNumeric(protocol)){
+                int protoNumber = Integer.parseInt(protocol);
+                if(protoNumber < 0 || protoNumber > 255){
+                    throw new InvalidParameterValueException("Invalid protocol 
number: " + protoNumber);
+                }
+            } else {
+                //Protocol is not number
+                //Check for valid protocol strings
+                String supportedProtocols = "tcp,udp,icmp,all";
+                if(!supportedProtocols.contains(protocol.toLowerCase())){
+                    throw new InvalidParameterValueException("Invalid 
protocol: " + protocol);
+                }
             }
-        }
 
-        // icmp code and icmp type can't be passed in for any other protocol 
rather than icmp
-        if (!protocol.equalsIgnoreCase(NetUtils.ICMP_PROTO) && (icmpCode != 
null || icmpType != null)) {
-            throw new InvalidParameterValueException("Can specify icmpCode and 
icmpType for ICMP protocol only");
-        }
+            // icmp code and icmp type can't be passed in for any other 
protocol rather than icmp
+            if (!protocol.equalsIgnoreCase(NetUtils.ICMP_PROTO) && (icmpCode 
!= null || icmpType != null)) {
+                throw new InvalidParameterValueException("Can specify icmpCode 
and icmpType for ICMP protocol only");
+            }
 
-        if (protocol.equalsIgnoreCase(NetUtils.ICMP_PROTO) && (portStart != 
null || portEnd != null)) {
-            throw new InvalidParameterValueException("Can't specify start/end 
port when protocol is ICMP");
+            if (protocol.equalsIgnoreCase(NetUtils.ICMP_PROTO) && (portStart 
!= null || portEnd != null)) {
+                throw new InvalidParameterValueException("Can't specify 
start/end port when protocol is ICMP");
+            }
         }
 
         //validate icmp code and type

Reply via email to