Ray Milkey
Committed by Gerrit Code Review

Sonar related fixes

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

Change-Id: I03992f89675f9d074347042b7a196dbcc1036c28
...@@ -15,8 +15,6 @@ ...@@ -15,8 +15,6 @@
15 */ 15 */
16 package org.onosproject.events; 16 package org.onosproject.events;
17 17
18 -import static java.util.stream.Collectors.toList;
19 -
20 import java.io.PrintWriter; 18 import java.io.PrintWriter;
21 import java.io.StringWriter; 19 import java.io.StringWriter;
22 import java.util.List; 20 import java.util.List;
...@@ -45,6 +43,9 @@ import com.fasterxml.jackson.databind.node.ObjectNode; ...@@ -45,6 +43,9 @@ import com.fasterxml.jackson.databind.node.ObjectNode;
45 import com.google.common.base.MoreObjects; 43 import com.google.common.base.MoreObjects;
46 import com.google.common.collect.ImmutableList; 44 import com.google.common.collect.ImmutableList;
47 45
46 +import static java.util.stream.Collectors.toList;
47 +import static org.onlab.util.SonarSuppressionConstants.SONAR_PRINT_STACK_TRACE;
48 +
48 /** 49 /**
49 * Command to print history of instance local ONOS Events. 50 * Command to print history of instance local ONOS Events.
50 */ 51 */
...@@ -161,6 +162,7 @@ public class EventsCommand ...@@ -161,6 +162,7 @@ public class EventsCommand
161 * 162 *
162 * @param json JSON node to print 163 * @param json JSON node to print
163 */ 164 */
165 + @java.lang.SuppressWarnings(SONAR_PRINT_STACK_TRACE)
164 private void printJson(JsonNode json) { 166 private void printJson(JsonNode json) {
165 try { 167 try {
166 print("%s", mapper().writerWithDefaultPrettyPrinter().writeValueAsString(json)); 168 print("%s", mapper().writerWithDefaultPrettyPrinter().writeValueAsString(json));
......
...@@ -16,11 +16,10 @@ ...@@ -16,11 +16,10 @@
16 */ 16 */
17 package org.onosproject.cli.net; 17 package org.onosproject.cli.net;
18 18
19 -import com.fasterxml.jackson.databind.ObjectMapper; 19 +import java.util.ArrayList;
20 -import com.fasterxml.jackson.databind.node.ArrayNode; 20 +import java.util.concurrent.CountDownLatch;
21 -import com.fasterxml.jackson.databind.node.ObjectNode; 21 +import java.util.concurrent.TimeUnit;
22 -import com.google.common.base.Stopwatch; 22 +
23 -import com.google.common.collect.Lists;
24 import org.apache.commons.lang.math.RandomUtils; 23 import org.apache.commons.lang.math.RandomUtils;
25 import org.apache.karaf.shell.commands.Argument; 24 import org.apache.karaf.shell.commands.Argument;
26 import org.apache.karaf.shell.commands.Command; 25 import org.apache.karaf.shell.commands.Command;
...@@ -41,9 +40,13 @@ import org.onosproject.net.flow.FlowRuleService; ...@@ -41,9 +40,13 @@ import org.onosproject.net.flow.FlowRuleService;
41 import org.onosproject.net.flow.TrafficSelector; 40 import org.onosproject.net.flow.TrafficSelector;
42 import org.onosproject.net.flow.TrafficTreatment; 41 import org.onosproject.net.flow.TrafficTreatment;
43 42
44 -import java.util.ArrayList; 43 +import com.fasterxml.jackson.databind.ObjectMapper;
45 -import java.util.concurrent.CountDownLatch; 44 +import com.fasterxml.jackson.databind.node.ArrayNode;
46 -import java.util.concurrent.TimeUnit; 45 +import com.fasterxml.jackson.databind.node.ObjectNode;
46 +import com.google.common.base.Stopwatch;
47 +import com.google.common.collect.Lists;
48 +
49 +import static org.onlab.util.SonarSuppressionConstants.SONAR_PRINT_STACK_TRACE;
47 50
48 /** 51 /**
49 * Installs bulk flows. 52 * Installs bulk flows.
...@@ -63,7 +66,7 @@ public class AddTestFlowsCommand extends AbstractShellCommand { ...@@ -63,7 +66,7 @@ public class AddTestFlowsCommand extends AbstractShellCommand {
63 String numOfRuns = null; 66 String numOfRuns = null;
64 67
65 @Override 68 @Override
66 - @java.lang.SuppressWarnings("squid:S1148") 69 + @java.lang.SuppressWarnings(SONAR_PRINT_STACK_TRACE)
67 protected void execute() { 70 protected void execute() {
68 FlowRuleService flowService = get(FlowRuleService.class); 71 FlowRuleService flowService = get(FlowRuleService.class);
69 DeviceService deviceService = get(DeviceService.class); 72 DeviceService deviceService = get(DeviceService.class);
......
...@@ -15,7 +15,10 @@ ...@@ -15,7 +15,10 @@
15 */ 15 */
16 package org.onosproject.app.impl; 16 package org.onosproject.app.impl;
17 17
18 -import com.google.common.collect.Maps; 18 +import java.io.InputStream;
19 +import java.util.Map;
20 +import java.util.Set;
21 +
19 import org.apache.felix.scr.annotations.Activate; 22 import org.apache.felix.scr.annotations.Activate;
20 import org.apache.felix.scr.annotations.Component; 23 import org.apache.felix.scr.annotations.Component;
21 import org.apache.felix.scr.annotations.Deactivate; 24 import org.apache.felix.scr.annotations.Deactivate;
...@@ -38,12 +41,14 @@ import org.onosproject.security.Permission; ...@@ -38,12 +41,14 @@ import org.onosproject.security.Permission;
38 import org.onosproject.security.SecurityUtil; 41 import org.onosproject.security.SecurityUtil;
39 import org.slf4j.Logger; 42 import org.slf4j.Logger;
40 43
41 -import java.io.InputStream; 44 +import com.google.common.collect.Maps;
42 -import java.util.Map;
43 -import java.util.Set;
44 45
45 import static com.google.common.base.Preconditions.checkNotNull; 46 import static com.google.common.base.Preconditions.checkNotNull;
46 -import static org.onosproject.app.ApplicationEvent.Type.*; 47 +import static org.onlab.util.SonarSuppressionConstants.SONAR_CALL_RUN;
48 +import static org.onosproject.app.ApplicationEvent.Type.APP_ACTIVATED;
49 +import static org.onosproject.app.ApplicationEvent.Type.APP_DEACTIVATED;
50 +import static org.onosproject.app.ApplicationEvent.Type.APP_INSTALLED;
51 +import static org.onosproject.app.ApplicationEvent.Type.APP_UNINSTALLED;
47 import static org.onosproject.security.AppGuard.checkPermission; 52 import static org.onosproject.security.AppGuard.checkPermission;
48 import static org.onosproject.security.AppPermission.Type.APP_READ; 53 import static org.onosproject.security.AppPermission.Type.APP_READ;
49 import static org.slf4j.LoggerFactory.getLogger; 54 import static org.slf4j.LoggerFactory.getLogger;
...@@ -276,7 +281,7 @@ public class ApplicationManager ...@@ -276,7 +281,7 @@ public class ApplicationManager
276 } 281 }
277 282
278 // Invokes the specified function, if not null. 283 // Invokes the specified function, if not null.
279 - @java.lang.SuppressWarnings("squid:S1217") // We really do mean to call run() 284 + @java.lang.SuppressWarnings(SONAR_CALL_RUN) // We really do mean to call run()
280 private void invokeHook(Runnable hook, ApplicationId appId) { 285 private void invokeHook(Runnable hook, ApplicationId appId) {
281 if (hook != null) { 286 if (hook != null) {
282 try { 287 try {
......
...@@ -15,21 +15,21 @@ ...@@ -15,21 +15,21 @@
15 */ 15 */
16 package org.onlab.packet; 16 package org.onlab.packet;
17 17
18 -import org.slf4j.Logger;
19 -
20 import java.nio.ByteBuffer; 18 import java.nio.ByteBuffer;
21 import java.util.ArrayList; 19 import java.util.ArrayList;
20 +import java.util.Arrays;
22 import java.util.HashMap; 21 import java.util.HashMap;
23 import java.util.List; 22 import java.util.List;
24 import java.util.Map; 23 import java.util.Map;
25 -import java.util.Arrays; 24 +
25 +import org.slf4j.Logger;
26 26
27 import static com.google.common.base.MoreObjects.toStringHelper; 27 import static com.google.common.base.MoreObjects.toStringHelper;
28 import static com.google.common.base.Preconditions.checkNotNull; 28 import static com.google.common.base.Preconditions.checkNotNull;
29 import static org.onlab.packet.PacketUtils.checkInput; 29 import static org.onlab.packet.PacketUtils.checkInput;
30 +import static org.onlab.util.SonarSuppressionConstants.SONAR_SWITCH_FALLTHROUGH;
30 import static org.slf4j.LoggerFactory.getLogger; 31 import static org.slf4j.LoggerFactory.getLogger;
31 32
32 -
33 /** 33 /**
34 * Implements IGMP control packet format. 34 * Implements IGMP control packet format.
35 */ 35 */
...@@ -156,7 +156,7 @@ public class IGMP extends BasePacket { ...@@ -156,7 +156,7 @@ public class IGMP extends BasePacket {
156 * 156 *
157 * @return the serialized IGMP message 157 * @return the serialized IGMP message
158 */ 158 */
159 - @java.lang.SuppressWarnings("squid:S128") // suppress switch fall through warning 159 + @java.lang.SuppressWarnings(SONAR_SWITCH_FALLTHROUGH) // suppress switch fall through warning
160 @Override 160 @Override
161 public byte[] serialize() { 161 public byte[] serialize() {
162 byte [] data = new byte[8915]; 162 byte [] data = new byte[8915];
......
...@@ -15,8 +15,6 @@ ...@@ -15,8 +15,6 @@
15 */ 15 */
16 package org.onlab.util; 16 package org.onlab.util;
17 17
18 -import org.slf4j.LoggerFactory;
19 -
20 import java.util.concurrent.Callable; 18 import java.util.concurrent.Callable;
21 import java.util.concurrent.Future; 19 import java.util.concurrent.Future;
22 import java.util.concurrent.LinkedBlockingQueue; 20 import java.util.concurrent.LinkedBlockingQueue;
...@@ -26,6 +24,10 @@ import java.util.concurrent.ThreadPoolExecutor; ...@@ -26,6 +24,10 @@ import java.util.concurrent.ThreadPoolExecutor;
26 import java.util.concurrent.TimeUnit; 24 import java.util.concurrent.TimeUnit;
27 import java.util.concurrent.atomic.AtomicLong; 25 import java.util.concurrent.atomic.AtomicLong;
28 26
27 +import org.slf4j.LoggerFactory;
28 +
29 +import static org.onlab.util.SonarSuppressionConstants.SONAR_CALL_RUN;
30 +
29 /** 31 /**
30 * Implementation of ThreadPoolExecutor that bounds the work queue. 32 * Implementation of ThreadPoolExecutor that bounds the work queue.
31 * <p> 33 * <p>
...@@ -137,7 +139,7 @@ public final class BoundedThreadPool extends ThreadPoolExecutor { ...@@ -137,7 +139,7 @@ public final class BoundedThreadPool extends ThreadPoolExecutor {
137 * Feedback policy that delays the caller's thread until the executor's work 139 * Feedback policy that delays the caller's thread until the executor's work
138 * queue falls below a threshold, then runs the job on the caller's thread. 140 * queue falls below a threshold, then runs the job on the caller's thread.
139 */ 141 */
140 - @java.lang.SuppressWarnings("squid:S1217") // We really do mean to call run() 142 + @java.lang.SuppressWarnings(SONAR_CALL_RUN) // We really do mean to call run()
141 private static final class CallerFeedbackPolicy implements RejectedExecutionHandler { 143 private static final class CallerFeedbackPolicy implements RejectedExecutionHandler {
142 144
143 private final BlockingBoolean underLoad = new BlockingBoolean(false); 145 private final BlockingBoolean underLoad = new BlockingBoolean(false);
......
...@@ -19,6 +19,8 @@ import java.util.function.Function; ...@@ -19,6 +19,8 @@ import java.util.function.Function;
19 19
20 import com.google.common.base.Throwables; 20 import com.google.common.base.Throwables;
21 21
22 +import static org.onlab.util.SonarSuppressionConstants.SONAR_CATCH_THROWABLE;
23 +
22 /** 24 /**
23 * Function that retries execution on failure. 25 * Function that retries execution on failure.
24 * 26 *
...@@ -42,7 +44,7 @@ public class RetryingFunction<U, V> implements Function<U, V> { ...@@ -42,7 +44,7 @@ public class RetryingFunction<U, V> implements Function<U, V> {
42 this.maxDelayBetweenRetries = maxDelayBetweenRetries; 44 this.maxDelayBetweenRetries = maxDelayBetweenRetries;
43 } 45 }
44 46
45 - @SuppressWarnings("squid:S1181") 47 + @SuppressWarnings(SONAR_CATCH_THROWABLE)
46 // Yes we really do want to catch Throwable 48 // Yes we really do want to catch Throwable
47 @Override 49 @Override
48 public V apply(U input) { 50 public V apply(U input) {
......
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onlab.util;
17 +
18 +/**
19 + * Constants to use to suppress SonarQube errors.
20 + */
21 +public final class SonarSuppressionConstants {
22 +
23 + public static final String SONAR_PRINT_STACK_TRACE = "squid:S1148";
24 + public static final String SONAR_SWITCH_FALLTHROUGH = "squid:S128";
25 + public static final String SONAR_CATCH_THROWABLE = "squid:S1181";
26 + public static final String SONAR_CALL_RUN = "squid:S1217";
27 +
28 + /*
29 + * Prohibit construction.
30 + */
31 + private SonarSuppressionConstants() {
32 +
33 + }
34 +}
...@@ -15,8 +15,6 @@ ...@@ -15,8 +15,6 @@
15 */ 15 */
16 package org.onlab.netty; 16 package org.onlab.netty;
17 17
18 -import static com.google.common.base.Preconditions.checkState;
19 -
20 import io.netty.buffer.ByteBuf; 18 import io.netty.buffer.ByteBuf;
21 import io.netty.channel.ChannelHandlerContext; 19 import io.netty.channel.ChannelHandlerContext;
22 import io.netty.handler.codec.ReplayingDecoder; 20 import io.netty.handler.codec.ReplayingDecoder;
...@@ -31,6 +29,9 @@ import org.slf4j.LoggerFactory; ...@@ -31,6 +29,9 @@ import org.slf4j.LoggerFactory;
31 29
32 import com.google.common.base.Charsets; 30 import com.google.common.base.Charsets;
33 31
32 +import static com.google.common.base.Preconditions.checkState;
33 +import static org.onlab.util.SonarSuppressionConstants.SONAR_SWITCH_FALLTHROUGH;
34 +
34 /** 35 /**
35 * Decoder for inbound messages. 36 * Decoder for inbound messages.
36 */ 37 */
...@@ -54,7 +55,7 @@ public class MessageDecoder extends ReplayingDecoder<DecoderState> { ...@@ -54,7 +55,7 @@ public class MessageDecoder extends ReplayingDecoder<DecoderState> {
54 } 55 }
55 56
56 @Override 57 @Override
57 - @java.lang.SuppressWarnings("squid:S128") // suppress switch fall through warning 58 + @java.lang.SuppressWarnings(SONAR_SWITCH_FALLTHROUGH) // suppress switch fall through warning
58 protected void decode( 59 protected void decode(
59 ChannelHandlerContext context, 60 ChannelHandlerContext context,
60 ByteBuf buffer, 61 ByteBuf buffer,
......
...@@ -15,10 +15,6 @@ ...@@ -15,10 +15,6 @@
15 */ 15 */
16 package org.onlab.netty; 16 package org.onlab.netty;
17 17
18 -import com.google.common.cache.Cache;
19 -import com.google.common.cache.CacheBuilder;
20 -import com.google.common.cache.RemovalListener;
21 -import com.google.common.cache.RemovalNotification;
22 import io.netty.bootstrap.Bootstrap; 18 import io.netty.bootstrap.Bootstrap;
23 import io.netty.bootstrap.ServerBootstrap; 19 import io.netty.bootstrap.ServerBootstrap;
24 import io.netty.buffer.PooledByteBufAllocator; 20 import io.netty.buffer.PooledByteBufAllocator;
...@@ -38,17 +34,7 @@ import io.netty.channel.nio.NioEventLoopGroup; ...@@ -38,17 +34,7 @@ import io.netty.channel.nio.NioEventLoopGroup;
38 import io.netty.channel.socket.SocketChannel; 34 import io.netty.channel.socket.SocketChannel;
39 import io.netty.channel.socket.nio.NioServerSocketChannel; 35 import io.netty.channel.socket.nio.NioServerSocketChannel;
40 import io.netty.channel.socket.nio.NioSocketChannel; 36 import io.netty.channel.socket.nio.NioSocketChannel;
41 -import org.apache.commons.pool.KeyedPoolableObjectFactory;
42 -import org.apache.commons.pool.impl.GenericKeyedObjectPool;
43 -import org.onosproject.store.cluster.messaging.Endpoint;
44 -import org.onosproject.store.cluster.messaging.MessagingService;
45 -import org.slf4j.Logger;
46 -import org.slf4j.LoggerFactory;
47 37
48 -import javax.net.ssl.KeyManagerFactory;
49 -import javax.net.ssl.SSLContext;
50 -import javax.net.ssl.SSLEngine;
51 -import javax.net.ssl.TrustManagerFactory;
52 import java.io.FileInputStream; 38 import java.io.FileInputStream;
53 import java.io.IOException; 39 import java.io.IOException;
54 import java.security.KeyStore; 40 import java.security.KeyStore;
...@@ -64,6 +50,25 @@ import java.util.concurrent.atomic.AtomicLong; ...@@ -64,6 +50,25 @@ import java.util.concurrent.atomic.AtomicLong;
64 import java.util.function.Consumer; 50 import java.util.function.Consumer;
65 import java.util.function.Function; 51 import java.util.function.Function;
66 52
53 +import javax.net.ssl.KeyManagerFactory;
54 +import javax.net.ssl.SSLContext;
55 +import javax.net.ssl.SSLEngine;
56 +import javax.net.ssl.TrustManagerFactory;
57 +
58 +import org.apache.commons.pool.KeyedPoolableObjectFactory;
59 +import org.apache.commons.pool.impl.GenericKeyedObjectPool;
60 +import org.onosproject.store.cluster.messaging.Endpoint;
61 +import org.onosproject.store.cluster.messaging.MessagingService;
62 +import org.slf4j.Logger;
63 +import org.slf4j.LoggerFactory;
64 +
65 +import com.google.common.cache.Cache;
66 +import com.google.common.cache.CacheBuilder;
67 +import com.google.common.cache.RemovalListener;
68 +import com.google.common.cache.RemovalNotification;
69 +
70 +import static org.onlab.util.SonarSuppressionConstants.SONAR_CATCH_THROWABLE;
71 +
67 /** 72 /**
68 * Implementation of MessagingService based on <a href="http://netty.io/">Netty</a> framework. 73 * Implementation of MessagingService based on <a href="http://netty.io/">Netty</a> framework.
69 */ 74 */
...@@ -106,7 +111,7 @@ public class NettyMessaging implements MessagingService { ...@@ -106,7 +111,7 @@ public class NettyMessaging implements MessagingService {
106 protected char[] ksPwd; 111 protected char[] ksPwd;
107 protected char[] tsPwd; 112 protected char[] tsPwd;
108 113
109 - @SuppressWarnings("squid:S1181") 114 + @SuppressWarnings(SONAR_CATCH_THROWABLE)
110 // We really need to catch Throwable due to netty native epoll() handling 115 // We really need to catch Throwable due to netty native epoll() handling
111 private void initEventLoopGroup() { 116 private void initEventLoopGroup() {
112 // try Epoll first and if that does work, use nio. 117 // try Epoll first and if that does work, use nio.
......