SONAR suggestion - generic exceptions

Replace uses of generic RuntimeException
with more appropriate unchecked exceptions

Change-Id: If283743c2cf7252b8d280bdb788708ebbe57da9d
diff --git a/apps/artemis/src/main/java/org/onosproject/artemis/impl/moas/MoasClientController.java b/apps/artemis/src/main/java/org/onosproject/artemis/impl/moas/MoasClientController.java
index fccda3e..7c1e01f 100644
--- a/apps/artemis/src/main/java/org/onosproject/artemis/impl/moas/MoasClientController.java
+++ b/apps/artemis/src/main/java/org/onosproject/artemis/impl/moas/MoasClientController.java
@@ -82,18 +82,13 @@
      * Bootstrap netty socket.
      *
      * @return bootstrap
-     * @throws Exception exception
      */
-    private Bootstrap createBootstrap() throws Exception {
-        try {
-            workerGroup = new NioEventLoopGroup();
-            return new Bootstrap()
-                    .group(workerGroup)
-                    .channel(NioSocketChannel.class)
-                    .option(ChannelOption.SO_KEEPALIVE, true);
-        } catch (Exception e) {
-            throw new Exception(e);
-        }
+    private Bootstrap createBootstrap() {
+        workerGroup = new NioEventLoopGroup();
+        return new Bootstrap()
+                .group(workerGroup)
+                .channel(NioSocketChannel.class)
+                .option(ChannelOption.SO_KEEPALIVE, true);
     }
 
     /**
diff --git a/apps/artemis/src/main/java/org/onosproject/artemis/impl/moas/MoasServerController.java b/apps/artemis/src/main/java/org/onosproject/artemis/impl/moas/MoasServerController.java
index c27a134..33e30d0 100644
--- a/apps/artemis/src/main/java/org/onosproject/artemis/impl/moas/MoasServerController.java
+++ b/apps/artemis/src/main/java/org/onosproject/artemis/impl/moas/MoasServerController.java
@@ -77,22 +77,17 @@
      * Create netty server bootstrap.
      *
      * @return bootstrap
-     * @throws Exception exception
      */
-    private ServerBootstrap createServerBootStrap() throws Exception {
-        try {
-            bossGroup = new NioEventLoopGroup();
-            workerGroup = new NioEventLoopGroup();
+    private ServerBootstrap createServerBootStrap() {
+        bossGroup = new NioEventLoopGroup();
+        workerGroup = new NioEventLoopGroup();
 
-            return new ServerBootstrap()
-                    .group(bossGroup, workerGroup)
-                    .channel(NioServerSocketChannel.class)
-                    .option(ChannelOption.SO_REUSEADDR, true)
-                    .childOption(ChannelOption.SO_KEEPALIVE, true)
-                    .childOption(ChannelOption.TCP_NODELAY, true);
-        } catch (Exception e) {
-            throw new Exception(e);
-        }
+        return new ServerBootstrap()
+                .group(bossGroup, workerGroup)
+                .channel(NioServerSocketChannel.class)
+                .option(ChannelOption.SO_REUSEADDR, true)
+                .childOption(ChannelOption.SO_KEEPALIVE, true)
+                .childOption(ChannelOption.TCP_NODELAY, true);
     }
 
     /**
diff --git a/apps/cpman/app/src/main/java/org/onosproject/cpman/impl/ControlMessageMetricMapper.java b/apps/cpman/app/src/main/java/org/onosproject/cpman/impl/ControlMessageMetricMapper.java
index bd541b4..92126bf 100644
--- a/apps/cpman/app/src/main/java/org/onosproject/cpman/impl/ControlMessageMetricMapper.java
+++ b/apps/cpman/app/src/main/java/org/onosproject/cpman/impl/ControlMessageMetricMapper.java
@@ -58,7 +58,7 @@
      */
     private static <I, O> O lookup(BiMap<I, O> map, I input, Class<O> cls) {
         if (!map.containsKey(input)) {
-            throw new RuntimeException(
+            throw new IllegalArgumentException(
                     String.format("No mapping found for %s when converting to %s",
                             input, cls.getName()));
         }
diff --git a/apps/l3vpn/src/main/java/org/onosproject/l3vpn/netl3vpn/impl/NetL3VpnManager.java b/apps/l3vpn/src/main/java/org/onosproject/l3vpn/netl3vpn/impl/NetL3VpnManager.java
index 0cb86ab..45e9f9b 100644
--- a/apps/l3vpn/src/main/java/org/onosproject/l3vpn/netl3vpn/impl/NetL3VpnManager.java
+++ b/apps/l3vpn/src/main/java/org/onosproject/l3vpn/netl3vpn/impl/NetL3VpnManager.java
@@ -240,7 +240,7 @@
             value = l3VpnIdGen.getNewId();
         }
         if (value > ID_LIMIT) {
-            throw new RuntimeException(ID_LIMIT_EXCEEDED);
+            throw new IllegalStateException(ID_LIMIT_EXCEEDED);
         }
         return CONS_HUNDRED + String.valueOf(value);
     }
diff --git a/apps/netconf/client/src/main/java/org/onosproject/netconf/client/impl/NetconfActiveComponent.java b/apps/netconf/client/src/main/java/org/onosproject/netconf/client/impl/NetconfActiveComponent.java
index 2c35f26..92043d5 100644
--- a/apps/netconf/client/src/main/java/org/onosproject/netconf/client/impl/NetconfActiveComponent.java
+++ b/apps/netconf/client/src/main/java/org/onosproject/netconf/client/impl/NetconfActiveComponent.java
@@ -212,7 +212,7 @@
         if (node.type() == DataNode.Type.SINGLE_INSTANCE_LEAF_VALUE_NODE) {
             temp = ((LeafNode) node).asString().split("\\:");
             if (temp.length != 3) {
-                throw new RuntimeException(new NetconfException("Invalid device id form, cannot apply"));
+                throw new IllegalStateException(new NetconfException("Invalid device id form, cannot apply"));
             }
             ip = temp[1];
             port = temp[2];
@@ -220,12 +220,12 @@
             ListKey key = (ListKey) node.key();
             temp = key.keyLeafs().get(0).leafValAsString().split("\\:");
             if (temp.length != 3) {
-                throw new RuntimeException(new NetconfException("Invalid device id form, cannot apply"));
+                throw new IllegalStateException(new NetconfException("Invalid device id form, cannot apply"));
             }
             ip = temp[1];
             port = temp[2];
         } else {
-            throw new RuntimeException(new NetconfException("Invalid device id type, cannot apply"));
+            throw new IllegalStateException(new NetconfException("Invalid device id type, cannot apply"));
         }
         try {
             return DeviceId.deviceId(new URI("netconf", ip + ":" + port, (String) null));
@@ -246,7 +246,7 @@
                 this.controller.connectDevice(deviceId);
                 //}
             } catch (Exception ex) {
-                throw new RuntimeException(new NetconfException("Unable to connect to NETCONF device on " +
+                throw new IllegalStateException(new NetconfException("Unable to connect to NETCONF device on " +
                         deviceId, ex));
             }
         }
@@ -263,21 +263,21 @@
         String resId = ResourceIdParser.parseResId(path);
         String[] el = resId.split(ResourceIdParser.EL_CHK);
         if (el.length < 3) {
-            throw new RuntimeException(new NetconfException("Invalid resource id, cannot apply"));
+            throw new IllegalStateException(new NetconfException("Invalid resource id, cannot apply"));
         }
         if (!el[2].contains((ResourceIdParser.KEY_SEP))) {
-            throw new RuntimeException(new NetconfException("Invalid device id key, cannot apply"));
+            throw new IllegalStateException(new NetconfException("Invalid device id key, cannot apply"));
         }
         String[] keys = el[2].split(ResourceIdParser.KEY_CHK);
         if (keys.length < 2) {
-            throw new RuntimeException(new NetconfException("Invalid device id key, cannot apply"));
+            throw new IllegalStateException(new NetconfException("Invalid device id key, cannot apply"));
         }
         String[] parts = keys[1].split(ResourceIdParser.NM_CHK);
         if (parts.length < 3) {
-            throw new RuntimeException(new NetconfException("Invalid device id key, cannot apply"));
+            throw new IllegalStateException(new NetconfException("Invalid device id key, cannot apply"));
         }
         if (parts[2].split("\\:").length != 3) {
-            throw new RuntimeException(new NetconfException("Invalid device id form, cannot apply"));
+            throw new IllegalStateException(new NetconfException("Invalid device id form, cannot apply"));
         }
         return (new ResourceId.Builder()
                 .addBranchPointSchema(el[1].split(ResourceIdParser.NM_CHK)[0],
@@ -299,23 +299,23 @@
         String resId = ResourceIdParser.parseResId(path);
         String[] el = resId.split(ResourceIdParser.EL_CHK);
         if (el.length < 3) {
-            throw new RuntimeException(new NetconfException("Invalid resource id, cannot apply"));
+            throw new IllegalStateException(new NetconfException("Invalid resource id, cannot apply"));
         }
         if (!el[2].contains((ResourceIdParser.KEY_SEP))) {
-            throw new RuntimeException(new NetconfException("Invalid device id key, cannot apply"));
+            throw new IllegalStateException(new NetconfException("Invalid device id key, cannot apply"));
         }
         String[] keys = el[2].split(ResourceIdParser.KEY_CHK);
         if (keys.length < 2) {
-            throw new RuntimeException(new NetconfException("Invalid device id key, cannot apply"));
+            throw new IllegalStateException(new NetconfException("Invalid device id key, cannot apply"));
         }
         String[] parts = keys[1].split(ResourceIdParser.NM_CHK);
         if (parts.length < 3) {
-            throw new RuntimeException(new NetconfException("Invalid device id key, cannot apply"));
+            throw new IllegalStateException(new NetconfException("Invalid device id key, cannot apply"));
         }
         String[] temp = parts[2].split("\\:");
         String ip, port;
         if (temp.length != 3) {
-            throw new RuntimeException(new NetconfException("Invalid device id form, cannot apply"));
+            throw new IllegalStateException(new NetconfException("Invalid device id form, cannot apply"));
         }
         ip = temp[1];
         port = temp[2];
diff --git a/apps/p4-tutorial/pipeconf/src/main/java/org/onosproject/p4tutorial/pipeconf/PipeconfFactory.java b/apps/p4-tutorial/pipeconf/src/main/java/org/onosproject/p4tutorial/pipeconf/PipeconfFactory.java
index a1e65aa..5d37bd1 100644
--- a/apps/p4-tutorial/pipeconf/src/main/java/org/onosproject/p4tutorial/pipeconf/PipeconfFactory.java
+++ b/apps/p4-tutorial/pipeconf/src/main/java/org/onosproject/p4tutorial/pipeconf/PipeconfFactory.java
@@ -67,7 +67,7 @@
         try {
             pipelineModel = P4InfoParser.parse(P4INFO_URL);
         } catch (P4InfoParserException e) {
-            throw new RuntimeException(e);
+            throw new IllegalStateException(e);
         }
 
         return DefaultPiPipeconf.builder()
diff --git a/apps/rabbitmq/src/main/java/org/onosproject/rabbitmq/impl/MQServiceImpl.java b/apps/rabbitmq/src/main/java/org/onosproject/rabbitmq/impl/MQServiceImpl.java
index 11b46fb..2ecc5d2 100644
--- a/apps/rabbitmq/src/main/java/org/onosproject/rabbitmq/impl/MQServiceImpl.java
+++ b/apps/rabbitmq/src/main/java/org/onosproject/rabbitmq/impl/MQServiceImpl.java
@@ -91,7 +91,7 @@
                                             prop.getProperty(SENDER_QUEUE)),
                     msgOutQueue);
         } catch (Exception e) {
-            throw new RuntimeException(e);
+            throw new IllegalStateException(e);
         }
         manageSender.start();
     }
diff --git a/apps/routing/fpm/app/src/main/java/org/onosproject/routing/fpm/protocol/RouteAttributeDst.java b/apps/routing/fpm/app/src/main/java/org/onosproject/routing/fpm/protocol/RouteAttributeDst.java
index 1535100..2962c0b 100644
--- a/apps/routing/fpm/app/src/main/java/org/onosproject/routing/fpm/protocol/RouteAttributeDst.java
+++ b/apps/routing/fpm/app/src/main/java/org/onosproject/routing/fpm/protocol/RouteAttributeDst.java
@@ -102,7 +102,7 @@
                 RouteAttribute.ROUTE_ATTRIBUTE_HEADER_LENGTH) {
             cb.writeBytes(buffer, Ip4Address.BYTE_LENGTH);
         } else {
-            throw new RuntimeException("Dst address length incorrect!");
+            throw new IllegalArgumentException("Dst address length incorrect!");
         }
     }
 }
diff --git a/apps/routing/fpm/app/src/main/java/org/onosproject/routing/fpm/protocol/RouteAttributeGateway.java b/apps/routing/fpm/app/src/main/java/org/onosproject/routing/fpm/protocol/RouteAttributeGateway.java
index 886f52e..3b1f5cd 100644
--- a/apps/routing/fpm/app/src/main/java/org/onosproject/routing/fpm/protocol/RouteAttributeGateway.java
+++ b/apps/routing/fpm/app/src/main/java/org/onosproject/routing/fpm/protocol/RouteAttributeGateway.java
@@ -104,7 +104,7 @@
                 RouteAttribute.ROUTE_ATTRIBUTE_HEADER_LENGTH) {
             cb.writeBytes(buffer, Ip4Address.BYTE_LENGTH);
         } else {
-            throw new RuntimeException("Gateway address length incorrect!");
+            throw new IllegalArgumentException("Gateway address length incorrect!");
         }
     }
 }
diff --git a/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/resources/FloatingIpWebResource.java b/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/resources/FloatingIpWebResource.java
index e958765..c510647 100644
--- a/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/resources/FloatingIpWebResource.java
+++ b/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/resources/FloatingIpWebResource.java
@@ -193,10 +193,8 @@
      *
      * @param floatingIpNodes the floatingIp json node
      * @return floatingIps a collection of floatingIp
-     * @throws Exception when any argument is illegal
      */
-    public Collection<FloatingIp> changeJsonToSub(JsonNode floatingIpNodes)
-            throws Exception {
+    public Collection<FloatingIp> changeJsonToSub(JsonNode floatingIpNodes) {
         checkNotNull(floatingIpNodes, JSON_NOT_NULL);
         Map<FloatingIpId, FloatingIp> subMap = new HashMap<FloatingIpId, FloatingIp>();
         if (!floatingIpNodes.hasNonNull("id")) {
diff --git a/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/resources/RouterWebResource.java b/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/resources/RouterWebResource.java
index c09b5cd..0d32a8d 100644
--- a/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/resources/RouterWebResource.java
+++ b/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/resources/RouterWebResource.java
@@ -131,7 +131,7 @@
             }
             return Response.status(CREATED).entity(result.toString()).build();
 
-        } catch (Exception e) {
+        } catch (IllegalArgumentException | IOException e) {
             return Response.status(BAD_REQUEST).entity(e.getMessage()).build();
         }
     }
@@ -271,8 +271,7 @@
         }
     }
 
-    private Collection<Router> createOrUpdateByInputStream(JsonNode subnode)
-            throws Exception {
+    private Collection<Router> createOrUpdateByInputStream(JsonNode subnode) {
         checkNotNull(subnode, JSON_NOT_NULL);
         JsonNode routerNode = subnode.get("routers");
         if (routerNode == null) {
@@ -281,7 +280,7 @@
         log.debug("routerNode is {}", routerNode.toString());
 
         if (routerNode.isArray()) {
-            throw new Exception("only singleton requests allowed");
+            throw new IllegalArgumentException("only singleton requests allowed");
         } else {
             return changeJsonToSub(routerNode);
         }
@@ -292,10 +291,8 @@
      *
      * @param routerNode the router json node
      * @return routers a collection of router
-     * @throws Exception when any argument is illegal
      */
-    public Collection<Router> changeJsonToSub(JsonNode routerNode)
-            throws Exception {
+    public Collection<Router> changeJsonToSub(JsonNode routerNode) {
         checkNotNull(routerNode, JSON_NOT_NULL);
         Map<RouterId, Router> subMap = new HashMap<RouterId, Router>();
         if (!routerNode.hasNonNull("id")) {
@@ -361,11 +358,9 @@
      * @param subnode the router json node
      * @param routerId the router identify
      * @return routers a collection of router
-     * @throws Exception when any argument is illegal
      */
     public Collection<Router> changeUpdateJsonToSub(JsonNode subnode,
-                                                    String routerId)
-                                                            throws Exception {
+                                                    String routerId) {
         checkNotNull(subnode, JSON_NOT_NULL);
         checkNotNull(routerId, "routerId should not be null");
         Map<RouterId, Router> subMap = new HashMap<RouterId, Router>();