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 @@
*/
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.fasterxml.jackson.databind.node.ObjectNode;
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 @@ public class EventsCommand
*
* @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));
......
......@@ -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.FlowRuleService;
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 @@ public class AddTestFlowsCommand extends AbstractShellCommand {
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);
......
......@@ -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.Permission;
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 @@ public class ApplicationManager
}
// 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 {
......
......@@ -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 @@ public class IGMP extends BasePacket {
*
* @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];
......
......@@ -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.ThreadPoolExecutor;
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 @@ public final class BoundedThreadPool extends ThreadPoolExecutor {
* 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);
......
......@@ -19,6 +19,8 @@ import java.util.function.Function;
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 @@ public class RetryingFunction<U, V> implements Function<U, V> {
this.maxDelayBetweenRetries = maxDelayBetweenRetries;
}
@SuppressWarnings("squid:S1181")
@SuppressWarnings(SONAR_CATCH_THROWABLE)
// Yes we really do want to catch Throwable
@Override
public V apply(U input) {
......
/*
* 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() {
}
}
......@@ -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 org.slf4j.LoggerFactory;
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 @@ public class MessageDecoder extends ReplayingDecoder<DecoderState> {
}
@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,
......
......@@ -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.nio.NioEventLoopGroup;
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.concurrent.atomic.AtomicLong;
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 @@ public class NettyMessaging implements MessagingService {
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.
......