Sonar related fixes

- suppress SONAR warning for printing stack trace in CLI
- add string constants for the Sonar suppression identifiers

Change-Id: I03992f89675f9d074347042b7a196dbcc1036c28
diff --git a/apps/events/src/main/java/org/onosproject/events/EventsCommand.java b/apps/events/src/main/java/org/onosproject/events/EventsCommand.java
index 67f8981..4d26466 100644
--- a/apps/events/src/main/java/org/onosproject/events/EventsCommand.java
+++ b/apps/events/src/main/java/org/onosproject/events/EventsCommand.java
@@ -15,8 +15,6 @@
  */
 package org.onosproject.events;
 
-import static java.util.stream.Collectors.toList;
-
 import java.io.PrintWriter;
 import java.io.StringWriter;
 import java.util.List;
@@ -45,6 +43,9 @@
 import com.google.common.base.MoreObjects;
 import com.google.common.collect.ImmutableList;
 
+import static java.util.stream.Collectors.toList;
+import static org.onlab.util.SonarSuppressionConstants.SONAR_PRINT_STACK_TRACE;
+
 /**
  * Command to print history of instance local ONOS Events.
  */
@@ -161,6 +162,7 @@
      *
      * @param json JSON node to print
      */
+    @java.lang.SuppressWarnings(SONAR_PRINT_STACK_TRACE)
     private void printJson(JsonNode json) {
         try {
             print("%s", mapper().writerWithDefaultPrettyPrinter().writeValueAsString(json));
diff --git a/cli/src/main/java/org/onosproject/cli/net/AddTestFlowsCommand.java b/cli/src/main/java/org/onosproject/cli/net/AddTestFlowsCommand.java
index 4a741ed..93939e9 100644
--- a/cli/src/main/java/org/onosproject/cli/net/AddTestFlowsCommand.java
+++ b/cli/src/main/java/org/onosproject/cli/net/AddTestFlowsCommand.java
@@ -16,11 +16,10 @@
  */
 package org.onosproject.cli.net;
 
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.node.ArrayNode;
-import com.fasterxml.jackson.databind.node.ObjectNode;
-import com.google.common.base.Stopwatch;
-import com.google.common.collect.Lists;
+import java.util.ArrayList;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
 import org.apache.commons.lang.math.RandomUtils;
 import org.apache.karaf.shell.commands.Argument;
 import org.apache.karaf.shell.commands.Command;
@@ -41,9 +40,13 @@
 import org.onosproject.net.flow.TrafficSelector;
 import org.onosproject.net.flow.TrafficTreatment;
 
-import java.util.ArrayList;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ArrayNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import com.google.common.base.Stopwatch;
+import com.google.common.collect.Lists;
+
+import static org.onlab.util.SonarSuppressionConstants.SONAR_PRINT_STACK_TRACE;
 
 /**
  * Installs bulk flows.
@@ -63,7 +66,7 @@
     String numOfRuns = null;
 
     @Override
-    @java.lang.SuppressWarnings("squid:S1148")
+    @java.lang.SuppressWarnings(SONAR_PRINT_STACK_TRACE)
     protected void execute() {
         FlowRuleService flowService = get(FlowRuleService.class);
         DeviceService deviceService = get(DeviceService.class);
diff --git a/core/net/src/main/java/org/onosproject/app/impl/ApplicationManager.java b/core/net/src/main/java/org/onosproject/app/impl/ApplicationManager.java
index 8fe804c..35555a1 100644
--- a/core/net/src/main/java/org/onosproject/app/impl/ApplicationManager.java
+++ b/core/net/src/main/java/org/onosproject/app/impl/ApplicationManager.java
@@ -15,7 +15,10 @@
  */
 package org.onosproject.app.impl;
 
-import com.google.common.collect.Maps;
+import java.io.InputStream;
+import java.util.Map;
+import java.util.Set;
+
 import org.apache.felix.scr.annotations.Activate;
 import org.apache.felix.scr.annotations.Component;
 import org.apache.felix.scr.annotations.Deactivate;
@@ -38,12 +41,14 @@
 import org.onosproject.security.SecurityUtil;
 import org.slf4j.Logger;
 
-import java.io.InputStream;
-import java.util.Map;
-import java.util.Set;
+import com.google.common.collect.Maps;
 
 import static com.google.common.base.Preconditions.checkNotNull;
-import static org.onosproject.app.ApplicationEvent.Type.*;
+import static org.onlab.util.SonarSuppressionConstants.SONAR_CALL_RUN;
+import static org.onosproject.app.ApplicationEvent.Type.APP_ACTIVATED;
+import static org.onosproject.app.ApplicationEvent.Type.APP_DEACTIVATED;
+import static org.onosproject.app.ApplicationEvent.Type.APP_INSTALLED;
+import static org.onosproject.app.ApplicationEvent.Type.APP_UNINSTALLED;
 import static org.onosproject.security.AppGuard.checkPermission;
 import static org.onosproject.security.AppPermission.Type.APP_READ;
 import static org.slf4j.LoggerFactory.getLogger;
@@ -276,7 +281,7 @@
     }
 
     // Invokes the specified function, if not null.
-    @java.lang.SuppressWarnings("squid:S1217") // We really do mean to call run()
+    @java.lang.SuppressWarnings(SONAR_CALL_RUN) // We really do mean to call run()
     private void invokeHook(Runnable hook, ApplicationId appId) {
         if (hook != null) {
             try {
diff --git a/utils/misc/src/main/java/org/onlab/packet/IGMP.java b/utils/misc/src/main/java/org/onlab/packet/IGMP.java
index cabd252..938cd6e 100644
--- a/utils/misc/src/main/java/org/onlab/packet/IGMP.java
+++ b/utils/misc/src/main/java/org/onlab/packet/IGMP.java
@@ -15,21 +15,21 @@
  */
 package org.onlab.packet;
 
-import org.slf4j.Logger;
-
 import java.nio.ByteBuffer;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-import java.util.Arrays;
+
+import org.slf4j.Logger;
 
 import static com.google.common.base.MoreObjects.toStringHelper;
 import static com.google.common.base.Preconditions.checkNotNull;
 import static org.onlab.packet.PacketUtils.checkInput;
+import static org.onlab.util.SonarSuppressionConstants.SONAR_SWITCH_FALLTHROUGH;
 import static org.slf4j.LoggerFactory.getLogger;
 
-
 /**
  * Implements IGMP control packet format.
  */
@@ -156,7 +156,7 @@
      *
      * @return the serialized IGMP message
      */
-    @java.lang.SuppressWarnings("squid:S128") // suppress switch fall through warning
+    @java.lang.SuppressWarnings(SONAR_SWITCH_FALLTHROUGH) // suppress switch fall through warning
     @Override
     public byte[] serialize() {
         byte [] data = new byte[8915];
diff --git a/utils/misc/src/main/java/org/onlab/util/BoundedThreadPool.java b/utils/misc/src/main/java/org/onlab/util/BoundedThreadPool.java
index 4364345..627f141 100644
--- a/utils/misc/src/main/java/org/onlab/util/BoundedThreadPool.java
+++ b/utils/misc/src/main/java/org/onlab/util/BoundedThreadPool.java
@@ -15,8 +15,6 @@
  */
 package org.onlab.util;
 
-import org.slf4j.LoggerFactory;
-
 import java.util.concurrent.Callable;
 import java.util.concurrent.Future;
 import java.util.concurrent.LinkedBlockingQueue;
@@ -26,6 +24,10 @@
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicLong;
 
+import org.slf4j.LoggerFactory;
+
+import static org.onlab.util.SonarSuppressionConstants.SONAR_CALL_RUN;
+
 /**
  * Implementation of ThreadPoolExecutor that bounds the work queue.
  * <p>
@@ -137,7 +139,7 @@
      * Feedback policy that delays the caller's thread until the executor's work
      * queue falls below a threshold, then runs the job on the caller's thread.
      */
-    @java.lang.SuppressWarnings("squid:S1217") // We really do mean to call run()
+    @java.lang.SuppressWarnings(SONAR_CALL_RUN) // We really do mean to call run()
     private static final class CallerFeedbackPolicy implements RejectedExecutionHandler {
 
         private final BlockingBoolean underLoad = new BlockingBoolean(false);
diff --git a/utils/misc/src/main/java/org/onlab/util/RetryingFunction.java b/utils/misc/src/main/java/org/onlab/util/RetryingFunction.java
index 1e32053..bb07c12 100644
--- a/utils/misc/src/main/java/org/onlab/util/RetryingFunction.java
+++ b/utils/misc/src/main/java/org/onlab/util/RetryingFunction.java
@@ -19,6 +19,8 @@
 
 import com.google.common.base.Throwables;
 
+import static org.onlab.util.SonarSuppressionConstants.SONAR_CATCH_THROWABLE;
+
 /**
  * Function that retries execution on failure.
  *
@@ -42,7 +44,7 @@
         this.maxDelayBetweenRetries = maxDelayBetweenRetries;
     }
 
-    @SuppressWarnings("squid:S1181")
+    @SuppressWarnings(SONAR_CATCH_THROWABLE)
     // Yes we really do want to catch Throwable
     @Override
     public V apply(U input) {
diff --git a/utils/misc/src/main/java/org/onlab/util/SonarSuppressionConstants.java b/utils/misc/src/main/java/org/onlab/util/SonarSuppressionConstants.java
new file mode 100644
index 0000000..d087e63
--- /dev/null
+++ b/utils/misc/src/main/java/org/onlab/util/SonarSuppressionConstants.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onlab.util;
+
+/**
+ * Constants to use to suppress SonarQube errors.
+ */
+public final class SonarSuppressionConstants {
+
+    public static final String SONAR_PRINT_STACK_TRACE = "squid:S1148";
+    public static final String SONAR_SWITCH_FALLTHROUGH = "squid:S128";
+    public static final String SONAR_CATCH_THROWABLE = "squid:S1181";
+    public static final String SONAR_CALL_RUN = "squid:S1217";
+
+    /*
+     * Prohibit construction.
+     */
+    private SonarSuppressionConstants() {
+
+    }
+}
diff --git a/utils/netty/src/main/java/org/onlab/netty/MessageDecoder.java b/utils/netty/src/main/java/org/onlab/netty/MessageDecoder.java
index a94a38b..e5382e1 100644
--- a/utils/netty/src/main/java/org/onlab/netty/MessageDecoder.java
+++ b/utils/netty/src/main/java/org/onlab/netty/MessageDecoder.java
@@ -15,8 +15,6 @@
  */
 package org.onlab.netty;
 
-import static com.google.common.base.Preconditions.checkState;
-
 import io.netty.buffer.ByteBuf;
 import io.netty.channel.ChannelHandlerContext;
 import io.netty.handler.codec.ReplayingDecoder;
@@ -31,6 +29,9 @@
 
 import com.google.common.base.Charsets;
 
+import static com.google.common.base.Preconditions.checkState;
+import static org.onlab.util.SonarSuppressionConstants.SONAR_SWITCH_FALLTHROUGH;
+
 /**
  * Decoder for inbound messages.
  */
@@ -54,7 +55,7 @@
     }
 
     @Override
-    @java.lang.SuppressWarnings("squid:S128") // suppress switch fall through warning
+    @java.lang.SuppressWarnings(SONAR_SWITCH_FALLTHROUGH) // suppress switch fall through warning
     protected void decode(
             ChannelHandlerContext context,
             ByteBuf buffer,
diff --git a/utils/netty/src/main/java/org/onlab/netty/NettyMessaging.java b/utils/netty/src/main/java/org/onlab/netty/NettyMessaging.java
index b9709cc..77d4a40 100644
--- a/utils/netty/src/main/java/org/onlab/netty/NettyMessaging.java
+++ b/utils/netty/src/main/java/org/onlab/netty/NettyMessaging.java
@@ -15,10 +15,6 @@
  */
 package org.onlab.netty;
 
-import com.google.common.cache.Cache;
-import com.google.common.cache.CacheBuilder;
-import com.google.common.cache.RemovalListener;
-import com.google.common.cache.RemovalNotification;
 import io.netty.bootstrap.Bootstrap;
 import io.netty.bootstrap.ServerBootstrap;
 import io.netty.buffer.PooledByteBufAllocator;
@@ -38,17 +34,7 @@
 import io.netty.channel.socket.SocketChannel;
 import io.netty.channel.socket.nio.NioServerSocketChannel;
 import io.netty.channel.socket.nio.NioSocketChannel;
-import org.apache.commons.pool.KeyedPoolableObjectFactory;
-import org.apache.commons.pool.impl.GenericKeyedObjectPool;
-import org.onosproject.store.cluster.messaging.Endpoint;
-import org.onosproject.store.cluster.messaging.MessagingService;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
-import javax.net.ssl.KeyManagerFactory;
-import javax.net.ssl.SSLContext;
-import javax.net.ssl.SSLEngine;
-import javax.net.ssl.TrustManagerFactory;
 import java.io.FileInputStream;
 import java.io.IOException;
 import java.security.KeyStore;
@@ -64,6 +50,25 @@
 import java.util.function.Consumer;
 import java.util.function.Function;
 
+import javax.net.ssl.KeyManagerFactory;
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.SSLEngine;
+import javax.net.ssl.TrustManagerFactory;
+
+import org.apache.commons.pool.KeyedPoolableObjectFactory;
+import org.apache.commons.pool.impl.GenericKeyedObjectPool;
+import org.onosproject.store.cluster.messaging.Endpoint;
+import org.onosproject.store.cluster.messaging.MessagingService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.cache.Cache;
+import com.google.common.cache.CacheBuilder;
+import com.google.common.cache.RemovalListener;
+import com.google.common.cache.RemovalNotification;
+
+import static org.onlab.util.SonarSuppressionConstants.SONAR_CATCH_THROWABLE;
+
 /**
  * Implementation of MessagingService based on <a href="http://netty.io/">Netty</a> framework.
  */
@@ -106,7 +111,7 @@
     protected char[] ksPwd;
     protected char[] tsPwd;
 
-    @SuppressWarnings("squid:S1181")
+    @SuppressWarnings(SONAR_CATCH_THROWABLE)
     // We really need to catch Throwable due to netty native epoll() handling
     private void initEventLoopGroup() {
         // try Epoll first and if that does work, use nio.