From f3064526ab982735bbd490da15246a2a4ce35de9 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Fri, 19 Jul 2019 17:19:57 +0200 Subject: [PATCH 1/1] Cleanup sonar-reported code smells This is a simple pass over reported issues, making trivial fixes. Change-Id: If2094f3e9b02ccfea407dd3eddc641937b186170 Signed-off-by: Robert Varga --- .../flowspec/AbstractFlowspecNlriParser.java | 2 +- .../ipv6/FlowspecL3vpnIpv6RIBSupport.java | 3 -- .../registry/BgpAttributeConditionsUtil.java | 35 ++++--------------- .../bgp/mode/impl/base/BaseBestPath.java | 8 +---- .../protocol/pcep/impl/PCEPSessionImpl.java | 8 ++--- .../pcep/pcc/mock/PCCSyncOptimization.java | 5 +-- .../pcep/spi/PCEPErrorIdentifier.java | 5 +-- .../config/PCEPTopologyProviderUtil.java | 4 --- .../provider/TopologyStatsProviderImpl.java | 2 +- 9 files changed, 16 insertions(+), 56 deletions(-) diff --git a/bgp/extensions/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/AbstractFlowspecNlriParser.java b/bgp/extensions/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/AbstractFlowspecNlriParser.java index 79cb599ae3..8dc6206814 100644 --- a/bgp/extensions/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/AbstractFlowspecNlriParser.java +++ b/bgp/extensions/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/AbstractFlowspecNlriParser.java @@ -561,7 +561,7 @@ public abstract class AbstractFlowspecNlriParser implements NlriParser, NlriSeri * @param nlri byte representation of NLRI which will be parsed * @return list of Flowspec */ - protected final List parseNlriFlowspecList(final @NonNull ByteBuf nlri) throws BGPParsingException { + protected final List parseNlriFlowspecList(final @NonNull ByteBuf nlri) { if (!nlri.isReadable()) { return null; } diff --git a/bgp/extensions/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/l3vpn/ipv6/FlowspecL3vpnIpv6RIBSupport.java b/bgp/extensions/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/l3vpn/ipv6/FlowspecL3vpnIpv6RIBSupport.java index 1c1d279e95..116ef3709c 100644 --- a/bgp/extensions/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/l3vpn/ipv6/FlowspecL3vpnIpv6RIBSupport.java +++ b/bgp/extensions/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/l3vpn/ipv6/FlowspecL3vpnIpv6RIBSupport.java @@ -15,7 +15,6 @@ import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSeriali import org.opendaylight.protocol.bgp.flowspec.SimpleFlowspecExtensionProviderContext; import org.opendaylight.protocol.bgp.flowspec.l3vpn.AbstractFlowspecL3vpnRIBSupport; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.bgp.rib.rib.loc.rib.tables.routes.FlowspecL3vpnIpv6RoutesCase; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.bgp.rib.rib.loc.rib.tables.routes.FlowspecL3vpnIpv6RoutesCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.flowspec.l3vpn.destination.ipv6.DestinationFlowspecL3vpnIpv6; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.flowspec.l3vpn.ipv6.route.FlowspecL3vpnRoute; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.flowspec.l3vpn.ipv6.route.FlowspecL3vpnRouteBuilder; @@ -35,8 +34,6 @@ public final class FlowspecL3vpnIpv6RIBSupport FlowspecL3vpnRouteKey> { private static final FlowspecL3vpnIpv6Routes EMPTY_CONTAINER = new FlowspecL3vpnIpv6RoutesBuilder().setFlowspecL3vpnRoute(Collections.emptyList()).build(); - private static final FlowspecL3vpnIpv6RoutesCase EMPTY_CASE = new FlowspecL3vpnIpv6RoutesCaseBuilder() - .setFlowspecL3vpnIpv6Routes(EMPTY_CONTAINER).build(); private static FlowspecL3vpnIpv6RIBSupport SINGLETON; private FlowspecL3vpnIpv6RIBSupport( diff --git a/bgp/openconfig-rp-spi/src/main/java/org/opendaylight/protocol/bgp/openconfig/routing/policy/spi/registry/BgpAttributeConditionsUtil.java b/bgp/openconfig-rp-spi/src/main/java/org/opendaylight/protocol/bgp/openconfig/routing/policy/spi/registry/BgpAttributeConditionsUtil.java index 42ba6b934e..2d374e4ace 100644 --- a/bgp/openconfig-rp-spi/src/main/java/org/opendaylight/protocol/bgp/openconfig/routing/policy/spi/registry/BgpAttributeConditionsUtil.java +++ b/bgp/openconfig-rp-spi/src/main/java/org/opendaylight/protocol/bgp/openconfig/routing/policy/spi/registry/BgpAttributeConditionsUtil.java @@ -45,39 +45,18 @@ final class BgpAttributeConditionsUtil { final Class afiSafi, final Attributes attributes, final BgpConditions conditions) { - if (!matchAfiSafi(afiSafi, conditions.getAfiSafiIn())) { - return false; - } - - if (!matchAsPathLength(attributes.getAsPath(), conditions.getAsPathLength())) { - return false; - } - - if (!matchMED(attributes.getMultiExitDisc(), conditions.getMedEq())) { - return false; - } - - if (!matchOrigin(attributes.getOrigin(), conditions.getOriginEq())) { - return false; - } - - if (!matchNextHopIn(attributes.getCNextHop(), conditions.getNextHopIn())) { - return false; - } - - if (!matchLocalPref(attributes.getLocalPref(), conditions.getLocalPrefEq())) { - return false; - } - return true; + return matchAfiSafi(afiSafi, conditions.getAfiSafiIn()) + && matchAsPathLength(attributes.getAsPath(), conditions.getAsPathLength()) + && matchMED(attributes.getMultiExitDisc(), conditions.getMedEq()) + && matchOrigin(attributes.getOrigin(), conditions.getOriginEq()) + && matchNextHopIn(attributes.getCNextHop(), conditions.getNextHopIn()) + && matchLocalPref(attributes.getLocalPref(), conditions.getLocalPrefEq()); } private static boolean matchAfiSafi( final Class afiSafi, final List> afiSafiIn) { - if (afiSafiIn == null) { - return true; - } - return afiSafiIn.contains(afiSafi); + return afiSafiIn == null ? true : afiSafiIn.contains(afiSafi); } private static boolean matchMED(final MultiExitDisc multiExitDisc, final Long med) { diff --git a/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/base/BaseBestPath.java b/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/base/BaseBestPath.java index 0306dcf5d2..9837d1c070 100644 --- a/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/base/BaseBestPath.java +++ b/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/base/BaseBestPath.java @@ -57,12 +57,6 @@ final class BaseBestPath extends AbstractBestPath { return false; } final BaseBestPath other = (BaseBestPath) obj; - if (!this.routerId.equals(other.routerId)) { - return false; - } - if (!this.state.equals(other.state)) { - return false; - } - return true; + return this.routerId.equals(other.routerId) && this.state.equals(other.state); } } diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPSessionImpl.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPSessionImpl.java index af69c48e58..c2cfc3f4e4 100644 --- a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPSessionImpl.java +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPSessionImpl.java @@ -403,7 +403,7 @@ public class PCEPSessionImpl extends SimpleChannelInboundHandler implem } @Override - public synchronized final void channelInactive(final ChannelHandlerContext ctx) { + public final synchronized void channelInactive(final ChannelHandlerContext ctx) { LOG.debug("Channel {} inactive.", ctx.channel()); endOfInput(); @@ -415,18 +415,18 @@ public class PCEPSessionImpl extends SimpleChannelInboundHandler implem } @Override - protected synchronized final void channelRead0(final ChannelHandlerContext ctx, final Message msg) { + protected final synchronized void channelRead0(final ChannelHandlerContext ctx, final Message msg) { LOG.debug("Message was received: {}", msg); handleMessage(msg); } @Override - public synchronized final void handlerAdded(final ChannelHandlerContext ctx) { + public final synchronized void handlerAdded(final ChannelHandlerContext ctx) { this.sessionUp(); } @Override - public synchronized void exceptionCaught(final ChannelHandlerContext ctx, final Throwable cause) { + public synchronized void exceptionCaught(final ChannelHandlerContext ctx, final Throwable cause) { handleException(cause); } diff --git a/pcep/pcc-mock/src/main/java/org/opendaylight/protocol/pcep/pcc/mock/PCCSyncOptimization.java b/pcep/pcc-mock/src/main/java/org/opendaylight/protocol/pcep/pcc/mock/PCCSyncOptimization.java index a3f2d835eb..eeb6f0b108 100644 --- a/pcep/pcc-mock/src/main/java/org/opendaylight/protocol/pcep/pcc/mock/PCCSyncOptimization.java +++ b/pcep/pcc-mock/src/main/java/org/opendaylight/protocol/pcep/pcc/mock/PCCSyncOptimization.java @@ -153,10 +153,7 @@ final class PCCSyncOptimization { } public boolean isSyncNeedIt() { - if (doesLspDbMatch() && !this.resynchronizing) { - return false; - } - return true; + return !doesLspDbMatch() || this.resynchronizing; } public void setResynchronizingState(final Boolean resync) { diff --git a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/PCEPErrorIdentifier.java b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/PCEPErrorIdentifier.java index e17a12fa3f..0871128d23 100644 --- a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/PCEPErrorIdentifier.java +++ b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/PCEPErrorIdentifier.java @@ -48,10 +48,7 @@ final class PCEPErrorIdentifier implements Serializable { return false; } final PCEPErrorIdentifier other = (PCEPErrorIdentifier) obj; - if (this.type != other.type || this.value != other.value) { - return false; - } - return true; + return this.type == other.type && this.value == other.value; } @Override diff --git a/pcep/topology/topology-provider/src/main/java/org/opendaylight/bgpcep/pcep/topology/provider/config/PCEPTopologyProviderUtil.java b/pcep/topology/topology-provider/src/main/java/org/opendaylight/bgpcep/pcep/topology/provider/config/PCEPTopologyProviderUtil.java index 5a1999b1cb..a7207c7a45 100644 --- a/pcep/topology/topology-provider/src/main/java/org/opendaylight/bgpcep/pcep/topology/provider/config/PCEPTopologyProviderUtil.java +++ b/pcep/topology/topology-provider/src/main/java/org/opendaylight/bgpcep/pcep/topology/provider/config/PCEPTopologyProviderUtil.java @@ -25,13 +25,9 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.sync.optimizations.config.rev181109.PcepNodeSyncConfig; import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology; import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.TopologyTypes; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; final class PCEPTopologyProviderUtil { - private static final Logger LOG = LoggerFactory.getLogger(PCEPTopologyProviderUtil.class); - private PCEPTopologyProviderUtil() { throw new UnsupportedOperationException(); } diff --git a/pcep/topology/topology-stats/src/main/java/org/opendaylight/bgpcep/pcep/topology/stats/provider/TopologyStatsProviderImpl.java b/pcep/topology/topology-stats/src/main/java/org/opendaylight/bgpcep/pcep/topology/stats/provider/TopologyStatsProviderImpl.java index ae6f3725d1..d3ff3eef50 100644 --- a/pcep/topology/topology-stats/src/main/java/org/opendaylight/bgpcep/pcep/topology/stats/provider/TopologyStatsProviderImpl.java +++ b/pcep/topology/topology-stats/src/main/java/org/opendaylight/bgpcep/pcep/topology/stats/provider/TopologyStatsProviderImpl.java @@ -149,7 +149,7 @@ public final class TopologyStatsProviderImpl implements TransactionChainListener try { wTx.commit().get(); } catch (final InterruptedException | ExecutionException e) { - LOG.warn("Failed to remove Pcep Node stats {}.", nodeId.getKey().getNodeId()); + LOG.warn("Failed to remove Pcep Node stats {}.", nodeId.getKey().getNodeId(), e); } } } -- 2.36.6