From: Dana Kutenicsova Date: Fri, 25 Jul 2014 21:27:46 +0000 (+0200) Subject: Fixed various small bugs found by Findbugs plugin. X-Git-Tag: release/helium~107^2 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=cdc357af656bbbee073558795fa39c55ab703ad6;p=bgpcep.git Fixed various small bugs found by Findbugs plugin. Change-Id: I343625bdb9efd2c0ffdfc12f6c0c9119f377041c Signed-off-by: Dana Kutenicsova --- diff --git a/bgp/parser-spi/src/main/java/org/opendaylight/protocol/bgp/parser/spi/pojo/SimpleNlriRegistry.java b/bgp/parser-spi/src/main/java/org/opendaylight/protocol/bgp/parser/spi/pojo/SimpleNlriRegistry.java index 73d5ff6c6a..40b6c2e457 100644 --- a/bgp/parser-spi/src/main/java/org/opendaylight/protocol/bgp/parser/spi/pojo/SimpleNlriRegistry.java +++ b/bgp/parser-spi/src/main/java/org/opendaylight/protocol/bgp/parser/spi/pojo/SimpleNlriRegistry.java @@ -57,7 +57,7 @@ final class SimpleNlriRegistry implements NlriRegistry { } synchronized AutoCloseable registerNlriSerializer(final Class nlriClass, final NlriSerializer serializer){ - final NlriParser prev = this.handlers.get(nlriClass); + final NlriSerializer prev = this.serializers.get(nlriClass); Preconditions.checkState(prev == null, "Serializer already bound to class " + prev); this.serializers.put(nlriClass, serializer); diff --git a/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/AbstractBGPSessionNegotiator.java b/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/AbstractBGPSessionNegotiator.java index 5bf1f7ade2..d99872f27c 100644 --- a/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/AbstractBGPSessionNegotiator.java +++ b/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/AbstractBGPSessionNegotiator.java @@ -90,7 +90,7 @@ public abstract class AbstractBGPSessionNegotiator extends AbstractSessionNegoti } @Override - protected void startNegotiation() { + protected synchronized void startNegotiation() { Preconditions.checkState(this.state == State.Idle); // Check if peer is configured in registry before retrieving preferences diff --git a/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/BGPSessionImpl.java b/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/BGPSessionImpl.java index beb1489d94..7ef25879f3 100644 --- a/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/BGPSessionImpl.java +++ b/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/BGPSessionImpl.java @@ -12,16 +12,12 @@ import com.google.common.base.Objects; import com.google.common.base.Objects.ToStringHelper; import com.google.common.base.Preconditions; import com.google.common.collect.Sets; - import io.netty.channel.Channel; - import java.io.IOException; import java.util.Date; import java.util.Set; import java.util.concurrent.TimeUnit; - import javax.annotation.concurrent.GuardedBy; - import org.opendaylight.protocol.bgp.parser.AsNumberUtil; import org.opendaylight.protocol.bgp.parser.BGPError; import org.opendaylight.protocol.bgp.parser.BGPSession; @@ -284,7 +280,7 @@ public class BGPSessionImpl extends AbstractProtocolSession implem protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) { toStringHelper.add("channel", this.channel); - toStringHelper.add("state", this.state); + toStringHelper.add("state", this.getState()); return toStringHelper; } diff --git a/bgp/util/src/main/java/org/opendaylight/protocol/bgp/util/HexDumpBGPFileParser.java b/bgp/util/src/main/java/org/opendaylight/protocol/bgp/util/HexDumpBGPFileParser.java index 432a9a88b7..4af24345fe 100644 --- a/bgp/util/src/main/java/org/opendaylight/protocol/bgp/util/HexDumpBGPFileParser.java +++ b/bgp/util/src/main/java/org/opendaylight/protocol/bgp/util/HexDumpBGPFileParser.java @@ -12,16 +12,13 @@ import com.google.common.base.Preconditions; import com.google.common.base.Strings; import com.google.common.collect.Lists; import com.google.common.io.CharStreams; - import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.List; - import javax.annotation.concurrent.Immutable; - import org.apache.commons.codec.DecoderException; import org.apache.commons.codec.binary.Hex; import org.opendaylight.protocol.util.ByteArray; @@ -87,7 +84,7 @@ public final class HexDumpBGPFileParser { try { message = Hex.decodeHex(hexMessage.toCharArray()); } catch (final DecoderException e) { - new IllegalArgumentException("Failed to decode message body", e); + throw new IllegalArgumentException("Failed to decode message body", e); } messages.add(message); idx = messageEndIdx; diff --git a/pcep/ietf-stateful02/src/main/java/org/opendaylight/protocol/pcep/ietf/stateful02/Stateful02PCRequestMessageParser.java b/pcep/ietf-stateful02/src/main/java/org/opendaylight/protocol/pcep/ietf/stateful02/Stateful02PCRequestMessageParser.java index 09ce406ad6..afbd0e6e18 100644 --- a/pcep/ietf-stateful02/src/main/java/org/opendaylight/protocol/pcep/ietf/stateful02/Stateful02PCRequestMessageParser.java +++ b/pcep/ietf-stateful02/src/main/java/org/opendaylight/protocol/pcep/ietf/stateful02/Stateful02PCRequestMessageParser.java @@ -8,11 +8,8 @@ package org.opendaylight.protocol.pcep.ietf.stateful02; import com.google.common.collect.Lists; - import io.netty.buffer.ByteBuf; - import java.util.List; - import org.opendaylight.protocol.pcep.impl.message.PCEPRequestMessageParser; import org.opendaylight.protocol.pcep.spi.ObjectRegistry; import org.opendaylight.protocol.pcep.spi.PCEPErrors; @@ -22,7 +19,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.cra import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.bandwidth.object.Bandwidth; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.bandwidth.object.BandwidthBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.classtype.object.ClassType; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.Xro; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.include.route.object.Iro; @@ -202,9 +198,8 @@ public final class Stateful02PCRequestMessageParser extends PCEPRequestMessagePa if (rp.isReoptimization() && builder.getBandwidth() != null - && builder.getReportedRoute().getBandwidth().getBandwidth() != new BandwidthBuilder().setBandwidth( - new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Bandwidth(new byte[] { 0 })).build() - && builder.getReportedRoute().getRro() == null) { + && builder.getReportedRoute().getBandwidth().getBandwidth() != new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Bandwidth(new byte[] { 0 }) + && builder.getReportedRoute().getRro() == null) { errors.add(createErrorMsg(PCEPErrors.RRO_MISSING, rp)); return null; } diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCEPRequestMessageParser.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCEPRequestMessageParser.java index 7fe6ab6fa9..924cffc81d 100644 --- a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCEPRequestMessageParser.java +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCEPRequestMessageParser.java @@ -9,12 +9,9 @@ package org.opendaylight.protocol.pcep.impl.message; import com.google.common.base.Preconditions; import com.google.common.collect.Lists; - import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; - import java.util.List; - import org.opendaylight.protocol.pcep.spi.AbstractMessageParser; import org.opendaylight.protocol.pcep.spi.MessageUtil; import org.opendaylight.protocol.pcep.spi.ObjectRegistry; @@ -25,7 +22,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.mes import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.bandwidth.object.Bandwidth; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.bandwidth.object.BandwidthBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.classtype.object.ClassType; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.object.EndpointsObj; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.Xro; @@ -72,7 +68,7 @@ public class PCEPRequestMessageParser extends AbstractMessageParser { if (msg.getRequests() == null || msg.getRequests().isEmpty()) { throw new IllegalArgumentException("Requests cannot be null or empty."); } - ByteBuf buffer = Unpooled.buffer(); + final ByteBuf buffer = Unpooled.buffer(); for (final Requests req : msg.getRequests()) { serializeObject(req.getRp(), buffer); if (req.getPathKeyExpansion() != null) { @@ -323,9 +319,9 @@ public class PCEPRequestMessageParser extends AbstractMessageParser { if (rp.isReoptimization() && builder.getBandwidth() != null - && builder.getReportedRoute().getBandwidth().getBandwidth() != new BandwidthBuilder().setBandwidth( - new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Bandwidth(new byte[] { 0 })).build() - && builder.getReportedRoute().getRro() == null) { + && builder.getReportedRoute().getBandwidth().getBandwidth() != + new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Bandwidth(new byte[] { 0 }) + && builder.getReportedRoute().getRro() == null) { errors.add(createErrorMsg(PCEPErrors.RRO_MISSING, rp)); return null; } diff --git a/pcep/topology-provider/src/main/java/org/opendaylight/bgpcep/pcep/topology/provider/Stateful02TopologySessionListener.java b/pcep/topology-provider/src/main/java/org/opendaylight/bgpcep/pcep/topology/provider/Stateful02TopologySessionListener.java index 7eb3dee1e2..002c194a6b 100644 --- a/pcep/topology-provider/src/main/java/org/opendaylight/bgpcep/pcep/topology/provider/Stateful02TopologySessionListener.java +++ b/pcep/topology-provider/src/main/java/org/opendaylight/bgpcep/pcep/topology/provider/Stateful02TopologySessionListener.java @@ -15,13 +15,10 @@ import com.google.common.collect.ImmutableList; import com.google.common.util.concurrent.AsyncFunction; import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; - import java.net.InetAddress; import java.nio.ByteBuffer; import java.util.Collections; - import javax.annotation.concurrent.GuardedBy; - import org.opendaylight.controller.md.sal.binding.api.WriteTransaction; import org.opendaylight.protocol.pcep.PCEPSession; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated._00.rev140113.PcinitiateBuilder; @@ -128,7 +125,7 @@ public class Stateful02TopologySessionListener extends AbstractTopologySessionLi final ReportedLspBuilder rlb = new ReportedLspBuilder(); rlb.addAugmentation(ReportedLsp1.class, new ReportedLsp1Builder().setLsp(lsp).build()); - org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.pcep.client.attributes.path.computation.client.reported.lsp.PathBuilder pb = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.pcep.client.attributes.path.computation.client.reported.lsp.PathBuilder(); + final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.pcep.client.attributes.path.computation.client.reported.lsp.PathBuilder pb = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.pcep.client.attributes.path.computation.client.reported.lsp.PathBuilder(); if (r.getPath() != null) { pb.fieldsFrom(r.getPath()); } @@ -169,7 +166,7 @@ public class Stateful02TopologySessionListener extends AbstractTopologySessionLi @Override public synchronized ListenableFuture addLsp(final AddLspArgs input) { - Preconditions.checkArgument(input != null && input.getName() != null & input.getNode() != null && input.getArguments() != null, "Mandatory XML tags are missing."); + Preconditions.checkArgument(input != null && input.getName() != null && input.getNode() != null && input.getArguments() != null, "Mandatory XML tags are missing."); // Make sure there is no such LSP final InstanceIdentifier lsp = lspIdentifier(input.getName()).build(); final ListenableFuture> f = readOperationalData(lsp); @@ -205,7 +202,7 @@ public class Stateful02TopologySessionListener extends AbstractTopologySessionLi @Override public synchronized ListenableFuture removeLsp(final RemoveLspArgs input) { - Preconditions.checkArgument(input != null && input.getName() != null & input.getNode() != null, "Mandatory XML tags are missing."); + Preconditions.checkArgument(input != null && input.getName() != null && input.getNode() != null, "Mandatory XML tags are missing."); // Make sure the LSP exists, we need it for PLSP-ID final InstanceIdentifier lsp = lspIdentifier(input.getName()).build(); final ListenableFuture> f = readOperationalData(lsp); @@ -220,7 +217,7 @@ public class Stateful02TopologySessionListener extends AbstractTopologySessionLi final ReportedLsp1 ra = rep.get().getAugmentation(ReportedLsp1.class); Preconditions.checkState(ra != null, "Reported LSP reported null from data-store."); - Lsp reportedLsp = ra.getLsp(); + final Lsp reportedLsp = ra.getLsp(); Preconditions.checkState(reportedLsp != null, "Reported LSP does not contain LSP object."); // Build the request and send it @@ -236,7 +233,7 @@ public class Stateful02TopologySessionListener extends AbstractTopologySessionLi @Override public synchronized ListenableFuture updateLsp(final UpdateLspArgs input) { - Preconditions.checkArgument(input != null && input.getName() != null & input.getNode() != null && input.getArguments() != null, "Mandatory XML tags are missing."); + Preconditions.checkArgument(input != null && input.getName() != null && input.getNode() != null && input.getArguments() != null, "Mandatory XML tags are missing."); // Make sure the LSP exists final InstanceIdentifier lsp = lspIdentifier(input.getName()).build(); final ListenableFuture> f = readOperationalData(lsp); @@ -251,9 +248,9 @@ public class Stateful02TopologySessionListener extends AbstractTopologySessionLi final ReportedLsp1 ra = rep.get().getAugmentation(ReportedLsp1.class); Preconditions.checkState(ra != null, "Reported LSP reported null from data-store."); - Lsp reportedLsp = ra.getLsp(); + final Lsp reportedLsp = ra.getLsp(); Preconditions.checkState(reportedLsp != null, "Reported LSP does not contain LSP object."); - Arguments2 args = input.getArguments().getAugmentation(Arguments2.class); + final Arguments2 args = input.getArguments().getAugmentation(Arguments2.class); Preconditions.checkArgument(args != null, "Input is missing operational tag."); Preconditions.checkArgument(input.getArguments().getEro() != null, "Input is missing ERO object."); @@ -272,7 +269,7 @@ public class Stateful02TopologySessionListener extends AbstractTopologySessionLi @Override public synchronized ListenableFuture ensureLspOperational(final EnsureLspOperationalInput input) { - Preconditions.checkArgument(input != null && input.getName() != null & input.getNode() != null && input.getArguments() != null, "Mandatory XML tags are missing."); + Preconditions.checkArgument(input != null && input.getName() != null && input.getNode() != null && input.getArguments() != null, "Mandatory XML tags are missing."); final Boolean op; final Arguments1 aa = input.getArguments().getAugmentation(Arguments1.class); if (aa == null) { @@ -300,7 +297,7 @@ public class Stateful02TopologySessionListener extends AbstractTopologySessionLi LOG.warn("Node {} LSP {} does not contain data", input.getNode(), input.getName()); return OperationResults.UNSENT; } - Lsp reportedLsp = ra.getLsp(); + final Lsp reportedLsp = ra.getLsp(); Preconditions.checkState(reportedLsp != null, "Reported LSP does not contain LSP object."); if (reportedLsp.isOperational().equals(op)) { return OperationResults.SUCCESS; diff --git a/pcep/topology-provider/src/main/java/org/opendaylight/bgpcep/pcep/topology/provider/Stateful07TopologySessionListener.java b/pcep/topology-provider/src/main/java/org/opendaylight/bgpcep/pcep/topology/provider/Stateful07TopologySessionListener.java index 911db95ed1..a3bd7c0f61 100644 --- a/pcep/topology-provider/src/main/java/org/opendaylight/bgpcep/pcep/topology/provider/Stateful07TopologySessionListener.java +++ b/pcep/topology-provider/src/main/java/org/opendaylight/bgpcep/pcep/topology/provider/Stateful07TopologySessionListener.java @@ -214,7 +214,7 @@ final class Stateful07TopologySessionListener extends AbstractTopologySessionLis @Override public synchronized ListenableFuture addLsp(final AddLspArgs input) { - Preconditions.checkArgument(input != null && input.getName() != null & input.getNode() != null && input.getArguments() != null, "Mandatory XML tags are missing."); + Preconditions.checkArgument(input != null && input.getName() != null && input.getNode() != null && input.getArguments() != null, "Mandatory XML tags are missing."); LOG.trace("AddLspArgs {}", input); // Make sure there is no such LSP final InstanceIdentifier lsp = lspIdentifier(input.getName()).build(); @@ -230,14 +230,14 @@ final class Stateful07TopologySessionListener extends AbstractTopologySessionLis // Build the request final RequestsBuilder rb = new RequestsBuilder(); - Arguments2 args = input.getArguments().getAugmentation(Arguments2.class); + final Arguments2 args = input.getArguments().getAugmentation(Arguments2.class); Preconditions.checkArgument(args != null, "Input is missing operational tag."); - Lsp inputLsp = args.getLsp(); + final Lsp inputLsp = args.getLsp(); Preconditions.checkArgument(inputLsp != null, "Reported LSP does not contain LSP object."); rb.fieldsFrom(input.getArguments()); - TlvsBuilder tlvsBuilder = new TlvsBuilder(); + final TlvsBuilder tlvsBuilder = new TlvsBuilder(); tlvsBuilder.setSymbolicPathName( new SymbolicPathNameBuilder().setPathName(new SymbolicPathName(input.getName().getBytes(Charsets.UTF_8))).build()); if (inputLsp.getTlvs() != null) { @@ -260,7 +260,7 @@ final class Stateful07TopologySessionListener extends AbstractTopologySessionLis @Override public synchronized ListenableFuture removeLsp(final RemoveLspArgs input) { - Preconditions.checkArgument(input != null && input.getName() != null & input.getNode() != null, "Mandatory XML tags are missing."); + Preconditions.checkArgument(input != null && input.getName() != null && input.getNode() != null, "Mandatory XML tags are missing."); LOG.trace("RemoveLspArgs {}", input); // Make sure the LSP exists, we need it for PLSP-ID final InstanceIdentifier lsp = lspIdentifier(input.getName()).build(); @@ -277,7 +277,7 @@ final class Stateful07TopologySessionListener extends AbstractTopologySessionLis // it doesn't matter how many lsps there are in the path list, we only need delegate & plspid that is the same in each path final Path1 ra = rep.get().getPath().get(0).getAugmentation(Path1.class); Preconditions.checkState(ra != null, "Reported LSP reported null from data-store."); - Lsp reportedLsp = ra.getLsp(); + final Lsp reportedLsp = ra.getLsp(); Preconditions.checkState(reportedLsp != null, "Reported LSP does not contain LSP object."); // Build the request and send it @@ -294,7 +294,7 @@ final class Stateful07TopologySessionListener extends AbstractTopologySessionLis @Override public synchronized ListenableFuture updateLsp(final UpdateLspArgs input) { - Preconditions.checkArgument(input != null && input.getName() != null & input.getNode() != null && input.getArguments() != null, "Mandatory XML tags are missing."); + Preconditions.checkArgument(input != null && input.getName() != null && input.getNode() != null && input.getArguments() != null, "Mandatory XML tags are missing."); LOG.trace("UpdateLspArgs {}", input); // Make sure the LSP exists final InstanceIdentifier lsp = lspIdentifier(input.getName()).build(); @@ -311,13 +311,13 @@ final class Stateful07TopologySessionListener extends AbstractTopologySessionLis // it doesn't matter how many lsps there are in the path list, we only need plspid that is the same in each path final Path1 ra = rep.get().getPath().get(0).getAugmentation(Path1.class); Preconditions.checkState(ra != null, "Reported LSP reported null from data-store."); - Lsp reportedLsp = ra.getLsp(); + final Lsp reportedLsp = ra.getLsp(); Preconditions.checkState(reportedLsp != null, "Reported LSP does not contain LSP object."); // Build the PCUpd request and send it final UpdatesBuilder rb = new UpdatesBuilder(); rb.setSrp(new SrpBuilder().setOperationId(nextRequest()).setProcessingRule(Boolean.TRUE).build()); - Lsp inputLsp = input.getArguments().getAugmentation(Arguments3.class).getLsp(); + final Lsp inputLsp = input.getArguments().getAugmentation(Arguments3.class).getLsp(); if (inputLsp != null) { rb.setLsp(new LspBuilder().setPlspId(reportedLsp.getPlspId()).setDelegate((inputLsp.isDelegate() != null) ? inputLsp.isDelegate() : false).setTlvs(inputLsp.getTlvs()).setAdministrative((inputLsp.isAdministrative() != null) ? inputLsp.isAdministrative() : false).build()); } else { @@ -336,7 +336,7 @@ final class Stateful07TopologySessionListener extends AbstractTopologySessionLis @Override public synchronized ListenableFuture ensureLspOperational(final EnsureLspOperationalInput input) { - Preconditions.checkArgument(input != null && input.getName() != null & input.getNode() != null && input.getArguments() != null, "Mandatory XML tags are missing."); + Preconditions.checkArgument(input != null && input.getName() != null && input.getNode() != null && input.getArguments() != null, "Mandatory XML tags are missing."); final OperationalStatus op; final Arguments1 aa = input.getArguments().getAugmentation(Arguments1.class); if (aa != null) { @@ -360,13 +360,13 @@ final class Stateful07TopologySessionListener extends AbstractTopologySessionLis // check if at least one of the paths has the same status as requested boolean operational = false; - for (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.pcep.client.attributes.path.computation.client.reported.lsp.Path p : rep.get().getPath()) { - Path1 p1 = p.getAugmentation(Path1.class); + for (final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.pcep.client.attributes.path.computation.client.reported.lsp.Path p : rep.get().getPath()) { + final Path1 p1 = p.getAugmentation(Path1.class); if (p1 == null) { LOG.warn("Node {} LSP {} does not contain data", input.getNode(), input.getName()); return OperationResults.UNSENT; } - Lsp l = p1.getLsp(); + final Lsp l = p1.getLsp(); if (l.getOperational().equals(op)) { operational = true; } diff --git a/pcep/topology-provider/src/test/java/org/opendaylight/bgpcep/pcep/topology/provider/ParserToSalTest.java b/pcep/topology-provider/src/test/java/org/opendaylight/bgpcep/pcep/topology/provider/ParserToSalTest.java index d35708e909..c3d819f72b 100644 --- a/pcep/topology-provider/src/test/java/org/opendaylight/bgpcep/pcep/topology/provider/ParserToSalTest.java +++ b/pcep/topology-provider/src/test/java/org/opendaylight/bgpcep/pcep/topology/provider/ParserToSalTest.java @@ -23,6 +23,7 @@ import io.netty.channel.EventLoop; import io.netty.util.concurrent.Promise; import java.net.InetSocketAddress; import java.net.SocketAddress; +import java.util.ArrayList; import java.util.List; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; @@ -91,7 +92,7 @@ public class ParserToSalTest extends AbstractDataBrokerTest { @Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); - + this.receivedMsgs = new ArrayList<>(); doAnswer(new Answer() { @Override public Object answer(final InvocationOnMock invocation) { diff --git a/pcep/tunnel-provider/src/main/java/org/opendaylight/bgpcep/pcep/tunnel/provider/NodeChangedListener.java b/pcep/tunnel-provider/src/main/java/org/opendaylight/bgpcep/pcep/tunnel/provider/NodeChangedListener.java index d7099509a8..9eabd2a990 100644 --- a/pcep/tunnel-provider/src/main/java/org/opendaylight/bgpcep/pcep/tunnel/provider/NodeChangedListener.java +++ b/pcep/tunnel-provider/src/main/java/org/opendaylight/bgpcep/pcep/tunnel/provider/NodeChangedListener.java @@ -12,11 +12,9 @@ import com.google.common.collect.Lists; import com.google.common.util.concurrent.FutureCallback; import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.JdkFutureAdapters; - import java.util.HashSet; import java.util.Map; import java.util.Set; - import org.opendaylight.controller.md.sal.common.api.TransactionStatus; import org.opendaylight.controller.md.sal.common.api.data.DataChangeEvent; import org.opendaylight.controller.sal.binding.api.data.DataChangeListener; @@ -139,7 +137,7 @@ public final class NodeChangedListener implements DataChangeListener { if (tpt instanceof Ip) { for (final IpAddress a : ((Ip) tpt).getIpAddress()) { - if (addr.equals(a.getIpv6Address())) { + if (addr.equals(a)) { if (sni != null) { final NodeKey k = InstanceIdentifier.keyOf(sni); boolean have = false; @@ -265,10 +263,10 @@ public final class NodeChangedListener implements DataChangeListener { LOG.debug("Searching for orphan links/nodes"); final Topology t = (Topology) trans.readOperationalData(this.target); - NodeId srcNode = l.getSource().getSourceNode(); - NodeId dstNode = l.getDestination().getDestNode(); - TpId srcTp = l.getSource().getSourceTp(); - TpId dstTp = l.getDestination().getDestTp(); + final NodeId srcNode = l.getSource().getSourceNode(); + final NodeId dstNode = l.getDestination().getDestNode(); + final TpId srcTp = l.getSource().getSourceTp(); + final TpId dstTp = l.getDestination().getDestTp(); boolean orphSrcNode = true, orphDstNode = true, orphDstTp = true, orphSrcTp = true; for (final Link lw : t.getLink()) { diff --git a/programming/impl/src/main/java/org/opendaylight/bgpcep/programming/impl/InstructionImpl.java b/programming/impl/src/main/java/org/opendaylight/bgpcep/programming/impl/InstructionImpl.java index 096a2d973c..e556a83d63 100644 --- a/programming/impl/src/main/java/org/opendaylight/bgpcep/programming/impl/InstructionImpl.java +++ b/programming/impl/src/main/java/org/opendaylight/bgpcep/programming/impl/InstructionImpl.java @@ -56,8 +56,8 @@ final class InstructionImpl implements Instruction { return id; } - InstructionStatus getStatus() { - return status; + synchronized InstructionStatus getStatus() { + return this.status; } synchronized void setStatus(final InstructionStatus status, final Details details) { diff --git a/programming/impl/src/main/java/org/opendaylight/bgpcep/programming/impl/ProgrammingServiceImpl.java b/programming/impl/src/main/java/org/opendaylight/bgpcep/programming/impl/ProgrammingServiceImpl.java index c482991cb3..fa69d7e501 100644 --- a/programming/impl/src/main/java/org/opendaylight/bgpcep/programming/impl/ProgrammingServiceImpl.java +++ b/programming/impl/src/main/java/org/opendaylight/bgpcep/programming/impl/ProgrammingServiceImpl.java @@ -191,10 +191,10 @@ public final class ProgrammingServiceImpl implements AutoCloseable, InstructionS } // The instruction is in a terminal state, we need to just unlink - // it from its dependencies and dependants + // it from its dependencies and dependents i.clean(); - insns.remove(i); + this.insns.remove(id); LOG.debug("Instruction {} cleaned successfully", id); } diff --git a/util/src/main/java/org/opendaylight/protocol/util/ByteArray.java b/util/src/main/java/org/opendaylight/protocol/util/ByteArray.java index 0db409e296..38f59021c5 100644 --- a/util/src/main/java/org/opendaylight/protocol/util/ByteArray.java +++ b/util/src/main/java/org/opendaylight/protocol/util/ByteArray.java @@ -9,9 +9,7 @@ package org.opendaylight.protocol.util; import com.google.common.base.Preconditions; import com.google.common.primitives.UnsignedInteger; - import io.netty.buffer.ByteBuf; - import java.io.File; import java.io.FileInputStream; import java.io.IOException; @@ -20,7 +18,6 @@ import java.nio.charset.CharacterCodingException; import java.nio.charset.Charset; import java.util.Arrays; import java.util.BitSet; - import org.apache.commons.codec.binary.Hex; /** @@ -38,10 +35,10 @@ public final class ByteArray { * @param length length of the returned byte array * @return byte array */ - public static byte[] readBytes(final ByteBuf buffer, int length) { - Preconditions.checkState(buffer != null && buffer.readableBytes() >= length, - "Buffer cannot be read for %s bytes. Contains only %s bytes.", length, buffer.readableBytes()); - byte[] result = new byte[length]; + public static byte[] readBytes(final ByteBuf buffer, final int length) { + Preconditions.checkArgument(buffer != null && buffer.readableBytes() >= length, + "Buffer cannot be read for %s bytes.", length); + final byte[] result = new byte[length]; buffer.readBytes(result); return result; } @@ -65,10 +62,10 @@ public final class ByteArray { * @param length length of the returned byte array * @return byte array */ - public static byte[] getBytes(final ByteBuf buffer, int length) { - Preconditions.checkState(buffer != null && buffer.readableBytes() >= length, - "Buffer cannot be read for %s bytes. Contains only %s bytes.", length, buffer.readableBytes()); - byte[] result = new byte[length]; + public static byte[] getBytes(final ByteBuf buffer, final int length) { + Preconditions.checkArgument(buffer != null && buffer.readableBytes() >= length, + "Buffer cannot be read for %s bytes.", length); + final byte[] result = new byte[length]; buffer.getBytes(buffer.readerIndex(), result); return result; } diff --git a/util/src/main/java/org/opendaylight/protocol/util/PCEPHexDumpParser.java b/util/src/main/java/org/opendaylight/protocol/util/PCEPHexDumpParser.java index 3d3d3ea921..fe22f9a36e 100644 --- a/util/src/main/java/org/opendaylight/protocol/util/PCEPHexDumpParser.java +++ b/util/src/main/java/org/opendaylight/protocol/util/PCEPHexDumpParser.java @@ -10,14 +10,12 @@ package org.opendaylight.protocol.util; import com.google.common.base.Preconditions; import com.google.common.collect.Lists; import com.google.common.io.CharStreams; - import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.List; - import org.apache.commons.codec.DecoderException; import org.apache.commons.codec.binary.Hex; import org.slf4j.Logger; @@ -62,21 +60,20 @@ public final class PCEPHexDumpParser { // next chars are final length, ending with '.' final int lengthIdx = idx + LENGTH.length(); final int messageIdx = content.indexOf('.', lengthIdx); - final int length = Integer.valueOf(content.substring(lengthIdx, messageIdx)); - final int messageEndIdx = idx + length * 2; + final int messageEndIdx = messageIdx + (length * 2) + 1; // dot // Assert that message is longer than minimum 4(header.length == 4) // If length in PCEP message would be 0, loop would never end Preconditions.checkArgument(length >= MINIMAL_LENGTH, "Invalid message at index " + idx + ", length atribute is lower than " + MINIMAL_LENGTH); - final String hexMessage = content.substring(idx, messageEndIdx); + final String hexMessage = content.substring(messageIdx + 1, messageEndIdx); // dot byte[] message = null; try { message = Hex.decodeHex(hexMessage.toCharArray()); } catch (final DecoderException e) { - new IllegalArgumentException("Failed to decode message", e); + throw new IllegalArgumentException("Failed to decode message", e); } messages.add(message); idx = messageEndIdx;