Ray Milkey
Committed by Gerrit Code Review

Revert changes to use constants for Sonar suppression

It turns out that suppression annotations have to have the actual
string literal in them; if you use a defined constant SonarQube
ignores the suppression.

Change-Id: I3628df116d182b01a108da0d6f059784a3be4fed
......@@ -44,7 +44,6 @@ 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.
......@@ -162,7 +161,7 @@ public class EventsCommand
*
* @param json JSON node to print
*/
@java.lang.SuppressWarnings(SONAR_PRINT_STACK_TRACE)
@java.lang.SuppressWarnings("squid:S1148")
private void printJson(JsonNode json) {
try {
print("%s", mapper().writerWithDefaultPrettyPrinter().writeValueAsString(json));
......
......@@ -46,8 +46,6 @@ 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.
*/
......@@ -66,7 +64,7 @@ public class AddTestFlowsCommand extends AbstractShellCommand {
String numOfRuns = null;
@Override
@java.lang.SuppressWarnings(SONAR_PRINT_STACK_TRACE)
@java.lang.SuppressWarnings("squid:S1148")
protected void execute() {
FlowRuleService flowService = get(FlowRuleService.class);
DeviceService deviceService = get(DeviceService.class);
......
......@@ -44,7 +44,6 @@ import org.slf4j.Logger;
import com.google.common.collect.Maps;
import static com.google.common.base.Preconditions.checkNotNull;
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;
......@@ -281,7 +280,7 @@ public class ApplicationManager
}
// Invokes the specified function, if not null.
@java.lang.SuppressWarnings(SONAR_CALL_RUN) // We really do mean to call run()
@java.lang.SuppressWarnings("squid:S1217") // We really do mean to call run()
private void invokeHook(Runnable hook, ApplicationId appId) {
if (hook != null) {
try {
......
......@@ -27,7 +27,6 @@ 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;
/**
......@@ -156,7 +155,7 @@ public class IGMP extends BasePacket {
*
* @return the serialized IGMP message
*/
@java.lang.SuppressWarnings(SONAR_SWITCH_FALLTHROUGH) // suppress switch fall through warning
@java.lang.SuppressWarnings("squid:S128") // suppress switch fall through warning
@Override
public byte[] serialize() {
byte[] data = new byte[8915];
......
......@@ -26,8 +26,6 @@ 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>
......@@ -139,7 +137,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(SONAR_CALL_RUN) // We really do mean to call run()
@java.lang.SuppressWarnings("squid:S1217") // We really do mean to call run()
private static final class CallerFeedbackPolicy implements RejectedExecutionHandler {
private final BlockingBoolean underLoad = new BlockingBoolean(false);
......
......@@ -19,8 +19,6 @@ 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.
*
......@@ -44,7 +42,7 @@ public class RetryingFunction<U, V> implements Function<U, V> {
this.maxDelayBetweenRetries = maxDelayBetweenRetries;
}
@SuppressWarnings(SONAR_CATCH_THROWABLE)
@SuppressWarnings("squid:S1181")
// 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() {
}
}
......@@ -30,7 +30,6 @@ 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.
......@@ -55,7 +54,7 @@ public class MessageDecoder extends ReplayingDecoder<DecoderState> {
}
@Override
@java.lang.SuppressWarnings(SONAR_SWITCH_FALLTHROUGH) // suppress switch fall through warning
@java.lang.SuppressWarnings("squid:S128") // suppress switch fall through warning
protected void decode(
ChannelHandlerContext context,
ByteBuf buffer,
......
......@@ -67,8 +67,6 @@ 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.
*/
......@@ -111,7 +109,7 @@ public class NettyMessaging implements MessagingService {
protected char[] ksPwd;
protected char[] tsPwd;
@SuppressWarnings(SONAR_CATCH_THROWABLE)
@SuppressWarnings("squid:S1181")
// 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.
......