From 676249ca1a4724f06b4781aedee490dbbbcfc20f Mon Sep 17 00:00:00 2001 From: Ray Milkey Date: Fri, 18 Dec 2015 09:27:03 -0800 Subject: [PATCH] Fix Sonar critical flagged bugs Change-Id: I60e9f72a1a66f65366d7dbc5335922e75097c9f3 --- .../app/impl/ApplicationManager.java | 1 + .../driver/handshaker/OFOpticalSwitch13.java | 4 +-- .../handshaker/OfOpticalSwitchImplLinc13.java | 3 +-- .../driver/netconf/XmlConfigParser.java | 2 +- .../incubator/rpc/grpc/GrpcDeviceUtils.java | 1 + .../bgpio/types/RouteDistinguisher.java | 25 ++++++++++++++++++- .../controller/driver/DefaultOvsdbClient.java | 8 +++--- .../ovsdb/rfc/utils/ConditionUtil.java | 2 +- .../src/main/java/org/onlab/packet/IGMP.java | 1 + .../org/onlab/util/BoundedThreadPool.java | 3 ++- .../java/org/onlab/netty/MessageDecoder.java | 1 + 11 files changed, 38 insertions(+), 13 deletions(-) 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 80a5ca779f..8fe804c9cd 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 @@ -276,6 +276,7 @@ public class ApplicationManager } // Invokes the specified function, if not null. + @java.lang.SuppressWarnings("squid:S1217") // We really do mean to call run() private void invokeHook(Runnable hook, ApplicationId appId) { if (hook != null) { try { diff --git a/drivers/src/main/java/org/onosproject/driver/handshaker/OFOpticalSwitch13.java b/drivers/src/main/java/org/onosproject/driver/handshaker/OFOpticalSwitch13.java index 5c6ce36039..c7409e92d5 100644 --- a/drivers/src/main/java/org/onosproject/driver/handshaker/OFOpticalSwitch13.java +++ b/drivers/src/main/java/org/onosproject/driver/handshaker/OFOpticalSwitch13.java @@ -70,9 +70,7 @@ public class OFOpticalSwitch13 extends AbstractOpenFlowSwitch implements OpenFlo try { sendHandshakeOFExperimenterPortDescRequest(); } catch (IOException e) { - log.error("Failed to send handshaker message OFExperimenterPortDescRequestfor sw {}, {}", - getStringId(), e.getMessage()); - e.printStackTrace(); + log.error("Failed to send handshaker message OFExperimenterPortDescRequestfor sw {}", e); } } diff --git a/drivers/src/main/java/org/onosproject/driver/handshaker/OfOpticalSwitchImplLinc13.java b/drivers/src/main/java/org/onosproject/driver/handshaker/OfOpticalSwitchImplLinc13.java index adcbb50c1a..5f8c82f9a5 100644 --- a/drivers/src/main/java/org/onosproject/driver/handshaker/OfOpticalSwitchImplLinc13.java +++ b/drivers/src/main/java/org/onosproject/driver/handshaker/OfOpticalSwitchImplLinc13.java @@ -96,8 +96,7 @@ public class OfOpticalSwitchImplLinc13 sendHandshakeOFExperimenterPortDescRequest(); } catch (IOException e) { log.error("LINC-OE exception while sending experimenter port desc:", - e.getMessage()); - e.printStackTrace(); + e); } } diff --git a/drivers/src/main/java/org/onosproject/driver/netconf/XmlConfigParser.java b/drivers/src/main/java/org/onosproject/driver/netconf/XmlConfigParser.java index 55826a258f..54430979c2 100644 --- a/drivers/src/main/java/org/onosproject/driver/netconf/XmlConfigParser.java +++ b/drivers/src/main/java/org/onosproject/driver/netconf/XmlConfigParser.java @@ -111,7 +111,7 @@ final class XmlConfigParser { try { editcfg.save(stringWriter); } catch (ConfigurationException e) { - e.printStackTrace(); + log.error("createControllersConfig()", e); } String s = stringWriter.toString() .replaceAll("", diff --git a/incubator/rpc-grpc/src/main/java/org/onosproject/incubator/rpc/grpc/GrpcDeviceUtils.java b/incubator/rpc-grpc/src/main/java/org/onosproject/incubator/rpc/grpc/GrpcDeviceUtils.java index 7045b0c2d9..aaf1e0bb4e 100644 --- a/incubator/rpc-grpc/src/main/java/org/onosproject/incubator/rpc/grpc/GrpcDeviceUtils.java +++ b/incubator/rpc-grpc/src/main/java/org/onosproject/incubator/rpc/grpc/GrpcDeviceUtils.java @@ -65,6 +65,7 @@ public final class GrpcDeviceUtils { return MastershipRole.STANDBY; case UNRECOGNIZED: log.warn("Unrecognized MastershipRole gRPC message: {}", role); + return MastershipRole.NONE; default: return MastershipRole.NONE; } diff --git a/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/RouteDistinguisher.java b/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/RouteDistinguisher.java index 37632ad8a4..36be714707 100644 --- a/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/RouteDistinguisher.java +++ b/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/RouteDistinguisher.java @@ -70,10 +70,33 @@ public class RouteDistinguisher implements Comparable { return ((Long) (this.getRouteDistinguisher())).compareTo((Long) (rd.getRouteDistinguisher())); } + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + + if (obj instanceof RouteDistinguisher) { + + RouteDistinguisher that = (RouteDistinguisher) obj; + + if (this.routeDistinguisher == that.routeDistinguisher) { + return true; + } + } + + return false; + } + + @Override + public int hashCode() { + return Long.hashCode(routeDistinguisher); + } + @Override public String toString() { return MoreObjects.toStringHelper(getClass()) .add("routeDistinguisher", routeDistinguisher) .toString(); } -} \ No newline at end of file +} diff --git a/protocols/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/driver/DefaultOvsdbClient.java b/protocols/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/driver/DefaultOvsdbClient.java index 0ede4a445a..16d9673d50 100644 --- a/protocols/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/driver/DefaultOvsdbClient.java +++ b/protocols/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/driver/DefaultOvsdbClient.java @@ -802,7 +802,7 @@ public class DefaultOvsdbClient operations.add(portInsert); // update the bridge table - Condition condition = ConditionUtil.equals("_uuid", UUID.uuid(bridgeUuid)); + Condition condition = ConditionUtil.isEqual("_uuid", UUID.uuid(bridgeUuid)); Mutation mutation = MutationUtil.insert("ports", UUID.uuid("Port")); List conditions = new ArrayList<>(Arrays.asList(condition)); List mutations = new ArrayList<>(Arrays.asList(mutation)); @@ -875,7 +875,7 @@ public class DefaultOvsdbClient } List conditions = Lists.newArrayList(); - Condition condition = ConditionUtil.equals(childColumnName, UUID.uuid(childUuid)); + Condition condition = ConditionUtil.isEqual(childColumnName, UUID.uuid(childUuid)); conditions.add(condition); Delete del = new Delete(childTableSchema, conditions); operations.add(del); @@ -898,7 +898,7 @@ public class DefaultOvsdbClient TableSchema tableSchema = dbSchema.getTableSchema(tableName); List conditions = Lists.newArrayList(); - Condition condition = ConditionUtil.equals(columnName, UUID.uuid(uuid)); + Condition condition = ConditionUtil.isEqual(columnName, UUID.uuid(uuid)); conditions.add(condition); Update update = new Update(tableSchema, row, conditions); @@ -944,7 +944,7 @@ public class DefaultOvsdbClient mutations.add(mutation); List conditions = Lists.newArrayList(); - Condition condition = ConditionUtil.equals("_uuid", + Condition condition = ConditionUtil.isEqual("_uuid", UUID.uuid(parentUuid)); conditions.add(condition); diff --git a/protocols/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/utils/ConditionUtil.java b/protocols/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/utils/ConditionUtil.java index 527b8bfe97..28e90848cf 100644 --- a/protocols/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/utils/ConditionUtil.java +++ b/protocols/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/utils/ConditionUtil.java @@ -37,7 +37,7 @@ public final class ConditionUtil { * @param data column value * @return Condition */ - public static Condition equals(String columnName, Object data) { + public static Condition isEqual(String columnName, Object data) { Object value = TransValueUtil.getFormatData(data); return new Condition(columnName, Function.EQUALS, value); } 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 594b79d094..cabd2527e4 100644 --- a/utils/misc/src/main/java/org/onlab/packet/IGMP.java +++ b/utils/misc/src/main/java/org/onlab/packet/IGMP.java @@ -156,6 +156,7 @@ public class IGMP extends BasePacket { * * @return the serialized IGMP message */ + @java.lang.SuppressWarnings("squid:S128") // 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 9eef6609a0..4364345ee7 100644 --- a/utils/misc/src/main/java/org/onlab/util/BoundedThreadPool.java +++ b/utils/misc/src/main/java/org/onlab/util/BoundedThreadPool.java @@ -137,6 +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("squid:S1217") // We really do mean to call run() private static final class CallerFeedbackPolicy implements RejectedExecutionHandler { private final BlockingBoolean underLoad = new BlockingBoolean(false); @@ -173,4 +174,4 @@ public final class BoundedThreadPool extends ThreadPoolExecutor { } } } -} \ No newline at end of file +} 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 af52a41c49..a94a38b50d 100644 --- a/utils/netty/src/main/java/org/onlab/netty/MessageDecoder.java +++ b/utils/netty/src/main/java/org/onlab/netty/MessageDecoder.java @@ -54,6 +54,7 @@ public class MessageDecoder extends ReplayingDecoder { } @Override + @java.lang.SuppressWarnings("squid:S128") // suppress switch fall through warning protected void decode( ChannelHandlerContext context, ByteBuf buffer,