Bug-731: pcep Tlv serializers - fixed sonar issues 83/8783/3
authorMilos Fabian <milfabia@cisco.com>
Tue, 8 Jul 2014 08:52:13 +0000 (10:52 +0200)
committerMilos Fabian <milfabia@cisco.com>
Tue, 8 Jul 2014 12:15:13 +0000 (14:15 +0200)
-no need to check for null before an insteadof
-fixed precondition checks in Tlv serializers

Change-Id: I8727f83beb713c427c0337b9058c00490631b1e8
Signed-off-by: Milos Fabian <milfabia@cisco.com>
22 files changed:
pcep/ietf-stateful02/src/main/java/org/opendaylight/protocol/pcep/crabbe/initiated00/LSPCleanupTlvParser.java
pcep/ietf-stateful02/src/main/java/org/opendaylight/protocol/pcep/crabbe/initiated00/PCEStatefulCapabilityTlvParser.java
pcep/ietf-stateful02/src/main/java/org/opendaylight/protocol/pcep/ietf/stateful02/Stateful02LspDbVersionTlvParser.java
pcep/ietf-stateful02/src/main/java/org/opendaylight/protocol/pcep/ietf/stateful02/Stateful02LspSymbolicNameTlvParser.java
pcep/ietf-stateful02/src/main/java/org/opendaylight/protocol/pcep/ietf/stateful02/Stateful02NodeIdentifierTlvParser.java
pcep/ietf-stateful02/src/main/java/org/opendaylight/protocol/pcep/ietf/stateful02/Stateful02RSVPErrorSpecTlvParser.java
pcep/ietf-stateful02/src/main/java/org/opendaylight/protocol/pcep/ietf/stateful02/Stateful02StatefulCapabilityTlvParser.java
pcep/ietf-stateful07/src/main/java/org/opendaylight/protocol/pcep/ietf/initiated00/CInitiated00StatefulCapabilityTlvParser.java
pcep/ietf-stateful07/src/main/java/org/opendaylight/protocol/pcep/ietf/stateful07/Stateful07LSPIdentifierIpv4TlvParser.java
pcep/ietf-stateful07/src/main/java/org/opendaylight/protocol/pcep/ietf/stateful07/Stateful07LSPIdentifierIpv6TlvParser.java
pcep/ietf-stateful07/src/main/java/org/opendaylight/protocol/pcep/ietf/stateful07/Stateful07LspSymbolicNameTlvParser.java
pcep/ietf-stateful07/src/main/java/org/opendaylight/protocol/pcep/ietf/stateful07/Stateful07LspUpdateErrorTlvParser.java
pcep/ietf-stateful07/src/main/java/org/opendaylight/protocol/pcep/ietf/stateful07/Stateful07RSVPErrorSpecTlvParser.java
pcep/ietf-stateful07/src/main/java/org/opendaylight/protocol/pcep/ietf/stateful07/Stateful07StatefulCapabilityTlvParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/AbstractVendorSpecificTlvParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/NoPathVectorTlvParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/OFListTlvParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/OrderTlvParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/OverloadedDurationTlvParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/ReqMissingTlvParser.java
pcep/segment-routing/src/main/java/org/opendaylight/protocol/pcep/lsp/setup/type01/PathSetupTypeTlvParser.java
pcep/segment-routing/src/main/java/org/opendaylight/protocol/pcep/segment/routing02/SrPceCapabilityTlvParser.java

index 563e4ac39e229e086aa804a52bdeae3ec53822df..6bf13973e587ff8160cd684c4683feef1f408668 100644 (file)
@@ -28,7 +28,7 @@ public final class LSPCleanupTlvParser implements TlvParser, TlvSerializer {
 
     @Override
     public void serializeTlv(final Tlv tlv, final ByteBuf buffer) {
-        Preconditions.checkArgument(tlv != null && tlv instanceof LspCleanup, "LSPCleanupTlv is mandatory.");
+        Preconditions.checkArgument(tlv instanceof LspCleanup, "LSPCleanupTlv is mandatory.");
         final ByteBuf body = Unpooled.buffer(CONTENT_LENGTH);
         writeUnsignedInt(((LspCleanup) tlv).getTimeout(), body);
         TlvUtil.formatTlv(TYPE, body, buffer);
index 0d9c96946c8dc80ef8065d19dd9026ce858c46fa..e02ad473832d385494b7a798679191e327d90af0 100644 (file)
@@ -54,7 +54,7 @@ public final class PCEStatefulCapabilityTlvParser extends Stateful02StatefulCapa
 
     @Override
     public void serializeTlv(final Tlv tlv, final ByteBuf buffer) {
-        Preconditions.checkArgument(tlv != null && tlv instanceof Stateful, "StatefulCapabilityTlv is mandatory.");
+        Preconditions.checkArgument(tlv instanceof Stateful, "StatefulCapabilityTlv is mandatory.");
         final Stateful sct = (Stateful) tlv;
         final ByteBuf body = Unpooled.buffer();
         final BitSet flags = new BitSet(FLAGS_F_LENGTH * Byte.SIZE);
index 4b26f83ccd1ce077328f739bf87a26d988278dae..8897fc18b22f4a0595dd74e5602ae73408b5e1d1 100644 (file)
@@ -40,7 +40,7 @@ public final class Stateful02LspDbVersionTlvParser implements TlvParser, TlvSeri
 
     @Override
     public void serializeTlv(final Tlv tlv, final ByteBuf buffer) {
-        Preconditions.checkArgument(tlv != null && tlv instanceof LspDbVersion, "LspDbVersionTlv is mandatory.");
+        Preconditions.checkArgument(tlv instanceof LspDbVersion, "LspDbVersionTlv is mandatory.");
         final ByteBuf body = Unpooled.buffer(CONTENT_LENGTH);
         final LspDbVersion ldvTlv = (LspDbVersion) tlv;
         Preconditions.checkArgument(ldvTlv.getVersion() != null, "Version is mandatory.");
index 9fc0a6073cdcf592c967d97da8d14ba2d0a96fa7..f73e025e7353a4a208369eacb00f452bfc0f2ea7 100644 (file)
@@ -37,7 +37,7 @@ public final class Stateful02LspSymbolicNameTlvParser implements TlvParser, TlvS
 
     @Override
     public void serializeTlv(final Tlv tlv, final ByteBuf buffer) {
-        Preconditions.checkArgument(tlv != null && tlv instanceof SymbolicPathName, "SymbolicPathNameTlv is mandatory.");
+        Preconditions.checkArgument(tlv instanceof SymbolicPathName, "SymbolicPathNameTlv is mandatory.");
         final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.SymbolicPathName spn = ((SymbolicPathName) tlv).getPathName();
         Preconditions.checkArgument(spn != null, "SymbolicPathName is mandatory");
         TlvUtil.formatTlv(TYPE, Unpooled.copiedBuffer(spn.getValue()), buffer);
index 299dc25059285eb18deb3c6844d45e3e5c8c25c8..6a0c69ce35ca6ea6f94d791b511a6c136c8bbc29 100644 (file)
@@ -25,7 +25,7 @@ public final class Stateful02NodeIdentifierTlvParser implements TlvParser, TlvSe
 
     @Override
     public void serializeTlv(final Tlv tlv, final ByteBuf buffer) {
-        Preconditions.checkArgument(tlv != null && tlv instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.node.identifier.tlv.NodeIdentifier, "NodeIdentifierTlv is mandatory.");
+        Preconditions.checkArgument(tlv instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.node.identifier.tlv.NodeIdentifier, "NodeIdentifierTlv is mandatory.");
         TlvUtil.formatTlv(TYPE, Unpooled.copiedBuffer(((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.node.identifier.tlv.NodeIdentifier) tlv).getNodeId().getValue()), buffer);
     }
 
index 7f0ba2338e7c848971b92b1428b896e619fab401..31e47fab39bb2c4f58375dd0d9d9cc33fdcbf5e5 100644 (file)
@@ -70,7 +70,7 @@ public final class Stateful02RSVPErrorSpecTlvParser implements TlvParser, TlvSer
 
     @Override
     public void serializeTlv(final Tlv tlv, final ByteBuf buffer) {
-        Preconditions.checkArgument(tlv != null, "RSVPErrorSpecTlv is mandatory.");
+        Preconditions.checkArgument(tlv instanceof RsvpErrorSpec, "RSVPErrorSpecTlv is mandatory.");
         final RsvpErrorSpec rsvpTlv = (RsvpErrorSpec) tlv;
         final RsvpError rsvp = rsvpTlv.getRsvpError();
         final ByteBuf body = Unpooled.buffer();
index b70e006e790df1d2fbc635df96b317cf88e3a4c6..a42c7e5b35af5343499a340301321469ad50a05c 100644 (file)
@@ -49,7 +49,7 @@ public class Stateful02StatefulCapabilityTlvParser implements TlvParser, TlvSeri
 
     @Override
     public void serializeTlv(final Tlv tlv, final ByteBuf buffer) {
-        Preconditions.checkArgument(tlv != null && tlv instanceof Stateful, "StatefulCapabilityTlv is mandatory.");
+        Preconditions.checkArgument(tlv instanceof Stateful, "StatefulCapabilityTlv is mandatory.");
         final Stateful sct = (Stateful) tlv;
         final ByteBuf body = Unpooled.buffer();
         final BitSet flags = new BitSet(FLAGS_F_LENGTH * Byte.SIZE);
index 81755f72ed1bbc07183808386757d2cb94a8857d..27ce9f9bd3c9529eee0a635ba0a5898a1498b5d2 100644 (file)
@@ -52,7 +52,7 @@ public final class CInitiated00StatefulCapabilityTlvParser extends Stateful07Sta
 
     @Override
     public void serializeTlv(final Tlv tlv, final ByteBuf buffer) {
-        Preconditions.checkArgument(tlv != null && tlv instanceof Stateful, "StatefulCapabilityTlv is mandatory.");
+        Preconditions.checkArgument(tlv instanceof Stateful, "StatefulCapabilityTlv is mandatory.");
         final Stateful sct = (Stateful) tlv;
         final ByteBuf body = Unpooled.buffer();
         final BitSet flags = new BitSet(FLAGS_F_LENGTH * Byte.SIZE);
index 53ca9098fec17ed36826f2e0f0c826b69b9636aa..c6df883afe22f5e7a3acca6587d40ae505b353ed 100644 (file)
@@ -65,7 +65,7 @@ public final class Stateful07LSPIdentifierIpv4TlvParser implements TlvParser, Tl
 
     @Override
     public void serializeTlv(final Tlv tlv, final ByteBuf buffer) {
-        Preconditions.checkArgument(tlv != null && tlv instanceof LspIdentifiers, "LspIdentifiersTlv is mandatory.");
+        Preconditions.checkArgument(tlv instanceof LspIdentifiers, "LspIdentifiersTlv is mandatory.");
         final LspIdentifiers lsp = (LspIdentifiers) tlv;
         final AddressFamily afi = lsp.getAddressFamily();
         final ByteBuf body = Unpooled.buffer();
index 296c9e4f0d34d5d90dc6209e50781ada24fe0b17..8c44ccd0839a71b04c639aa17e8c89e1679a3d5c 100644 (file)
@@ -64,7 +64,7 @@ public final class Stateful07LSPIdentifierIpv6TlvParser implements TlvParser, Tl
 
     @Override
     public void serializeTlv(final Tlv tlv, final ByteBuf buffer) {
-        Preconditions.checkArgument(tlv != null && tlv instanceof LspIdentifiers, "LspIdentifiersTlv is mandatory.");
+        Preconditions.checkArgument(tlv instanceof LspIdentifiers, "LspIdentifiersTlv is mandatory.");
         final LspIdentifiers lsp = (LspIdentifiers) tlv;
         final ByteBuf body = Unpooled.buffer();
         final Ipv6 ipv6 = ((Ipv6Case) lsp.getAddressFamily()).getIpv6();
index f2bfc1880a76e0327d44ce9bc6cc51cce5e5f377..32a62aac72893ffbb65adbd2145a034982374265 100644 (file)
@@ -37,7 +37,7 @@ public final class Stateful07LspSymbolicNameTlvParser implements TlvParser, TlvS
 
     @Override
     public void serializeTlv(final Tlv tlv, final ByteBuf buffer) {
-        Preconditions.checkArgument(tlv != null && tlv instanceof SymbolicPathName, "SymbolicPathNameTlv is mandatory.");
+        Preconditions.checkArgument(tlv instanceof SymbolicPathName, "SymbolicPathNameTlv is mandatory.");
         final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.SymbolicPathName spn = ((SymbolicPathName) tlv).getPathName();
         Preconditions.checkArgument(spn != null, "SymbolicPathName is mandatory");
         TlvUtil.formatTlv(TYPE, Unpooled.copiedBuffer(spn.getValue()), buffer);
index 9e8eecf9021c39b577e196a2c8e64fb38d21baa7..f2484a1368d56d14ba59bdf7c01572018c0ca9f3 100644 (file)
@@ -39,7 +39,7 @@ public final class Stateful07LspUpdateErrorTlvParser implements TlvParser, TlvSe
 
     @Override
     public void serializeTlv(final Tlv tlv, final ByteBuf buffer) {
-        Preconditions.checkArgument(tlv != null && tlv instanceof LspErrorCode, "LspErrorCodeTlv is mandatory.");
+        Preconditions.checkArgument(tlv instanceof LspErrorCode, "LspErrorCodeTlv is mandatory.");
         final ByteBuf body = Unpooled.buffer(CONTENT_LENGTH);
         writeUnsignedInt(((LspErrorCode) tlv).getErrorCode(), body);
         TlvUtil.formatTlv(TYPE, body, buffer);
index 9ea37f184810a902e6c8219abb71365c75958105..2232a3430d8702bf6d496e02b2e46cf54f62b5eb 100644 (file)
@@ -79,7 +79,7 @@ public final class Stateful07RSVPErrorSpecTlvParser implements TlvParser, TlvSer
 
     @Override
     public void serializeTlv(final Tlv tlv, final ByteBuf buffer) {
-        Preconditions.checkArgument(tlv != null, "RSVPErrorSpecTlv is mandatory.");
+        Preconditions.checkArgument(tlv instanceof RsvpErrorSpec, "RSVPErrorSpecTlv is mandatory.");
         final RsvpErrorSpec rsvp = (RsvpErrorSpec) tlv;
         final ByteBuf body = Unpooled.buffer();
         if (rsvp.getErrorType().getImplementedInterface().equals(RsvpCase.class)) {
index e21f99031fbab7a6bc74b3b6c378bb092e577d66..ecddf39e2423674fc1a978fcfbe52dffd0a0e545 100644 (file)
@@ -51,7 +51,7 @@ public class Stateful07StatefulCapabilityTlvParser implements TlvParser, TlvSeri
 
     @Override
     public void serializeTlv(final Tlv tlv, final ByteBuf buffer) {
-        Preconditions.checkArgument(tlv != null && tlv instanceof Stateful, "StatefulCapabilityTlv is mandatory.");
+        Preconditions.checkArgument(tlv instanceof Stateful, "StatefulCapabilityTlv is mandatory.");
         final Stateful sct = (Stateful) tlv;
         final ByteBuf body = Unpooled.buffer();
         final BitSet flags = new BitSet(FLAGS_F_LENGTH * Byte.SIZE);
index 512587cd42cf7f331f6b96ab48757f5af373d90b..870740afc57b5059ce3939e74de8b5570ae4c8c3 100644 (file)
@@ -30,7 +30,7 @@ public abstract class AbstractVendorSpecificTlvParser implements TlvParser, TlvS
 
     @Override
     public void serializeTlv(final Tlv tlv, final ByteBuf buffer) {
-        Preconditions.checkArgument(tlv != null, "Vendor Specific Tlv is mandatory.");
+        Preconditions.checkArgument(tlv instanceof VsTlv, "Vendor Specific Tlv is mandatory.");
         final VsTlv vsTlv = (VsTlv) tlv;
         final ByteBuf body = Unpooled.buffer();
         if (vsTlv.getEnterpriseNumber().getValue() == getEnterpriseNumber()) {
index 721536453d96507f43fde01ae74ddaf69da848a0..84ad0f116e05c866bc74208ffb90630662208f37 100644 (file)
@@ -56,7 +56,7 @@ public class NoPathVectorTlvParser implements TlvParser, TlvSerializer {
 
     @Override
     public void serializeTlv(final Tlv tlv, final ByteBuf buffer) {
-        Preconditions.checkArgument(tlv != null, "NoPathVectorTlv is mandatory.");
+        Preconditions.checkArgument(tlv instanceof NoPathVector, "NoPathVectorTlv is mandatory.");
         final NoPathVector noPath = (NoPathVector) tlv;
         final ByteBuf body = Unpooled.buffer();
         final BitSet flags = new BitSet(FLAGS_F_LENGTH * Byte.SIZE);
index e2afdffd235af306eb722aad2bd93cdf19dea5e0..7e5031c93082e92afd0aea53a1574eae2db34704 100644 (file)
@@ -49,7 +49,7 @@ public class OFListTlvParser implements TlvParser, TlvSerializer {
 
     @Override
     public void serializeTlv(final Tlv tlv, final ByteBuf buffer) {
-        Preconditions.checkArgument(tlv != null, "OFListTlv is mandatory.");
+        Preconditions.checkArgument(tlv instanceof OfList, "OFListTlv is mandatory.");
         final OfList oft = (OfList) tlv;
         final ByteBuf body = Unpooled.buffer();
         final List<OfId> ofCodes = oft.getCodes();
index 26d1c019e22290e0be5b6a886bef9f05b52f2ed2..694aef576e29ff3cabdee637c90ea12c95501416 100644 (file)
@@ -37,7 +37,7 @@ public class OrderTlvParser implements TlvParser, TlvSerializer {
 
     @Override
     public void serializeTlv(final Tlv tlv, final ByteBuf buffer) {
-        Preconditions.checkArgument(tlv != null, "OrderTlv is mandatory.");
+        Preconditions.checkArgument(tlv instanceof Order, "OrderTlv is mandatory.");
         final Order otlv = (Order) tlv;
         final ByteBuf body = Unpooled.buffer();
         writeUnsignedInt(otlv.getDelete(), body);
index aa354340082fc7897dbb32dc045ac79261504026..1075895e09ef3772fee6a98b35900eaab63421bb 100644 (file)
@@ -37,7 +37,7 @@ public class OverloadedDurationTlvParser implements TlvParser, TlvSerializer {
 
     @Override
     public void serializeTlv(final Tlv tlv, final ByteBuf buffer) {
-        Preconditions.checkArgument(tlv != null, "OverloadedTlv is mandatory.");
+        Preconditions.checkArgument(tlv instanceof OverloadDuration, "OverloadedTlv is mandatory.");
         final ByteBuf body = Unpooled.buffer();
         writeUnsignedInt(((OverloadDuration) tlv).getDuration(), body);
         TlvUtil.formatTlv(TYPE, body, buffer);
index 7523db5cec0abd3f5114fb055531040b02d73f69..91fddc1472a326f2875fabbe9973dfbf6314d6d9 100644 (file)
@@ -38,7 +38,7 @@ public class ReqMissingTlvParser implements TlvParser, TlvSerializer {
 
     @Override
     public void serializeTlv(final Tlv tlv, final ByteBuf buffer) {
-        Preconditions.checkArgument(tlv != null, "ReqMissingTlv is mandatory.");
+        Preconditions.checkArgument(tlv instanceof ReqMissing, "ReqMissingTlv is mandatory.");
         final ReqMissing req = (ReqMissing) tlv;
         final ByteBuf body = Unpooled.buffer();
         Preconditions.checkArgument(req.getRequestId() != null, "RequestId is mandatory.");
index 413dce36996a3ae5340032fbf87712976ab4c050..2783fd1b45a7ff60dc43084d54c4608bd90bd552 100644 (file)
@@ -30,7 +30,7 @@ public class PathSetupTypeTlvParser implements TlvParser, TlvSerializer {
 
     @Override
     public void serializeTlv(final Tlv tlv, final ByteBuf buffer) {
-        Preconditions.checkArgument(tlv != null && tlv instanceof PathSetupType, "PathSetupType is mandatory.");
+        Preconditions.checkArgument(tlv instanceof PathSetupType, "PathSetupType is mandatory.");
         final PathSetupType pstTlv = (PathSetupType) tlv;
         ByteBuf body = Unpooled.buffer(CONTENT_LENGTH);
         body.writeZero(OFFSET);
index d3afbae1aa48d49bd739c0d02298f8016faee6e7..9ecc8d31831efa61e1bd7c0ff8b0dad25d0b12f7 100644 (file)
@@ -30,7 +30,7 @@ public class SrPceCapabilityTlvParser implements TlvParser, TlvSerializer {
 
     @Override
     public void serializeTlv(final Tlv tlv, final ByteBuf buffer) {
-        Preconditions.checkArgument(tlv != null && tlv instanceof SrPceCapability, "SrPceCapability is mandatory.");
+        Preconditions.checkArgument(tlv instanceof SrPceCapability, "SrPceCapability is mandatory.");
         final ByteBuf body = Unpooled.buffer(CONTENT_LENGTH);
         body.writerIndex(OFFSET);
         writeUnsignedByte(((SrPceCapability) tlv).getMsd(), body);