Fixed failing build after yangtools update (List fields are by default not null). 99/9199/2
authorDana Kutenicsova <dkutenic@cisco.com>
Mon, 21 Jul 2014 12:56:04 +0000 (14:56 +0200)
committerDana Kutenicsova <dkutenic@cisco.com>
Mon, 21 Jul 2014 13:33:21 +0000 (15:33 +0200)
- added checks for empty

Change-Id: I1a6eb2481f85ce895e2c17a229b11cf8f0ba2fc4
Signed-off-by: Dana Kutenicsova <dkutenic@cisco.com>
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/LinkstateAttributeParser.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/CommunitiesAttributeParser.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/ExtendedCommunitiesAttributeParser.java
programming/impl/src/test/java/org/opendaylight/bgpcep/programming/impl/ProgrammingServiceImplTest.java

index 60b9e9aa52e22e2f948b5b5407a25d7332b9bdc9..6e717436978efc3d5a7c7a55d829448feed5782c 100644 (file)
@@ -301,7 +301,7 @@ public class LinkstateAttributeParser implements AttributeParser, AttributeSeria
                 final BitSet flags = BitSet.valueOf(ByteArray.readAllBytes(value));
                 builder.setNodeFlags(new NodeFlagBits(flags.get(OVERLOAD_BIT), flags.get(ATTACHED_BIT), flags.get(EXTERNAL_BIT), flags.get(ABBR_BIT)));
                 LOG.debug("Parsed Overload bit: {}, attached bit: {}, external bit: {}, area border router: {}.",
-                    flags.get(OVERLOAD_BIT), flags.get(ATTACHED_BIT), flags.get(EXTERNAL_BIT), flags.get(ABBR_BIT));
+                        flags.get(OVERLOAD_BIT), flags.get(ATTACHED_BIT), flags.get(EXTERNAL_BIT), flags.get(ABBR_BIT));
                 break;
             case TlvCode.NODE_OPAQUE:
                 LOG.debug("Ignoring opaque value: {}.", ByteBufUtil.hexDump(value));
@@ -376,7 +376,7 @@ public class LinkstateAttributeParser implements AttributeParser, AttributeSeria
                 LOG.debug("Parsed Metric: {}", metric);
                 break;
             case TlvCode.FORWARDING_ADDRESS:
-                IpAddress fwdAddress = parseForwardingAddress(value);
+                final IpAddress fwdAddress = parseForwardingAddress(value);
                 builder.setOspfForwardingAddress(fwdAddress);
                 LOG.debug("Parsed FWD Address: {}", fwdAddress);
                 break;
@@ -458,9 +458,10 @@ public class LinkstateAttributeParser implements AttributeParser, AttributeSeria
             writeTLV(TlvCode.MAX_RESERVABLE_BANDWIDTH, Unpooled.wrappedBuffer(linkAttributes.getMaxReservableBandwidth().getValue()), byteAggregator);
         }
         // this sub-TLV contains eight 32-bit IEEE floating point numbers
-        if (linkAttributes.getUnreservedBandwidth() != null) {
+        final List<UnreservedBandwidth> ubList = linkAttributes.getUnreservedBandwidth();
+        if (ubList != null && !ubList.isEmpty()) {
             final ByteBuf unreservedBandwithBuf = Unpooled.buffer();
-            for (final UnreservedBandwidth unreservedBandwidth : linkAttributes.getUnreservedBandwidth()) {
+            for (final UnreservedBandwidth unreservedBandwidth : ubList) {
                 unreservedBandwithBuf.writeBytes(unreservedBandwidth.getBandwidth().getValue());
             }
             writeTLV(TlvCode.UNRESERVED_BANDWIDTH, unreservedBandwithBuf, byteAggregator);
@@ -476,9 +477,10 @@ public class LinkstateAttributeParser implements AttributeParser, AttributeSeria
             // size of metric can be 1,2 or 3 depending on the protocol
             writeTLV(TlvCode.METRIC, Unpooled.copyMedium(linkAttributes.getMetric().getValue().intValue()), byteAggregator);
         }
-        if (linkAttributes.getSharedRiskLinkGroups() != null) {
+        final List<SrlgId> srlgList = linkAttributes.getSharedRiskLinkGroups();
+        if (srlgList != null && !srlgList.isEmpty()) {
             final ByteBuf sharedRLGBuf = Unpooled.buffer();
-            for (final SrlgId srlgId : linkAttributes.getSharedRiskLinkGroups()) {
+            for (final SrlgId srlgId : srlgList) {
                 sharedRLGBuf.writeInt(srlgId.getValue().intValue());
             }
             writeTLV(TlvCode.SHARED_RISK_LINK_GROUP, sharedRLGBuf, byteAggregator);
@@ -507,9 +509,10 @@ public class LinkstateAttributeParser implements AttributeParser, AttributeSeria
     private void serializeNodeAttributes(final NodeAttributesCase nodeAttributesCase, final ByteBuf byteAggregator) {
         LOG.trace("Started serializing Node Attributes");
         final NodeAttributes nodeAttributes = nodeAttributesCase.getNodeAttributes();
-        if (nodeAttributes.getTopologyIdentifier() != null) {
+        final List<TopologyIdentifier> topList = nodeAttributes.getTopologyIdentifier();
+        if (topList != null && !topList.isEmpty()) {
             final ByteBuf mpIdBuf = Unpooled.buffer();
-            for (final TopologyIdentifier topologyIdentifier : nodeAttributes.getTopologyIdentifier()) {
+            for (final TopologyIdentifier topologyIdentifier : topList) {
                 mpIdBuf.writeShort(topologyIdentifier.getValue());
             }
             writeTLV(TlvCode.MULTI_TOPOLOGY_ID, mpIdBuf, byteAggregator);
@@ -518,8 +521,9 @@ public class LinkstateAttributeParser implements AttributeParser, AttributeSeria
         if (nodeAttributes.getDynamicHostname() != null) {
             writeTLV(TlvCode.DYNAMIC_HOSTNAME, Unpooled.wrappedBuffer(nodeAttributes.getDynamicHostname().getBytes()), byteAggregator);
         }
-        if (nodeAttributes.getIsisAreaId() != null) {
-            for (final IsisAreaIdentifier isisAreaIdentifier : nodeAttributes.getIsisAreaId()) {
+        final List<IsisAreaIdentifier> isisList = nodeAttributes.getIsisAreaId();
+        if (isisList != null && !isisList.isEmpty()) {
+            for (final IsisAreaIdentifier isisAreaIdentifier : isisList) {
                 writeTLV(TlvCode.ISIS_AREA_IDENTIFIER, Unpooled.wrappedBuffer(isisAreaIdentifier.getValue()), byteAggregator);
             }
         }
@@ -570,9 +574,10 @@ public class LinkstateAttributeParser implements AttributeParser, AttributeSeria
             }
             writeTLV(TlvCode.ROUTE_TAG, routeTagsBuf, byteAggregator);
         }
-        if (prefixAtrributes.getExtendedTags() != null) {
+        final List<ExtendedRouteTag> routeTagList = prefixAtrributes.getExtendedTags();
+        if (routeTagList != null && !routeTagList.isEmpty()) {
             final ByteBuf extendedBuf = Unpooled.buffer();
-            for (final ExtendedRouteTag extendedRouteTag : prefixAtrributes.getExtendedTags()) {
+            for (final ExtendedRouteTag extendedRouteTag : routeTagList) {
                 extendedBuf.writeBytes(extendedRouteTag.getValue());
             }
             writeTLV(TlvCode.EXTENDED_ROUTE_TAG, extendedBuf, byteAggregator);
index 103d66c5a60e2997cfcc8f22aae8245eb145dbd2..9e513bc4eef0b86852a0c0b7288eda1b18d36229 100644 (file)
@@ -9,12 +9,9 @@ package org.opendaylight.protocol.bgp.parser.impl.message.update;
 
 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.bgp.parser.BGPDocumentedException;
 import org.opendaylight.protocol.bgp.parser.spi.AttributeParser;
 import org.opendaylight.protocol.bgp.parser.spi.AttributeSerializer;
@@ -52,7 +49,7 @@ public final class CommunitiesAttributeParser implements AttributeParser, Attrib
     public void serializeAttribute(final DataObject attribute, final ByteBuf byteAggregator) {
         final PathAttributes pathAttributes = (PathAttributes) attribute;
         final List<Communities> communities = pathAttributes.getCommunities();
-        if (communities == null) {
+        if (communities == null || communities.isEmpty()) {
             return;
         }
         final ByteBuf communitiesBuffer = Unpooled.buffer();
index 1ceac2a964e0414148d351da4a4e030465665326..4dc7ded5c35be6fd6dc8e6eb8a356ebc83619b5e 100644 (file)
@@ -9,12 +9,9 @@ package org.opendaylight.protocol.bgp.parser.impl.message.update;
 
 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.bgp.parser.BGPDocumentedException;
 import org.opendaylight.protocol.bgp.parser.spi.AttributeParser;
 import org.opendaylight.protocol.bgp.parser.spi.AttributeSerializer;
@@ -56,7 +53,7 @@ public final class ExtendedCommunitiesAttributeParser implements AttributeParser
     public void serializeAttribute(final DataObject attribute, final ByteBuf byteAggregator) {
         final PathAttributes pathAttributes = (PathAttributes) attribute;
         final List<ExtendedCommunities> communitiesList = pathAttributes.getExtendedCommunities();
-        if (communitiesList == null) {
+        if (communitiesList == null || communitiesList.isEmpty()) {
             return;
         }
         final ByteBuf extendedCommunitiesBuffer = Unpooled.buffer();
index ae20c3bb33638e943c05e6c26ef4929d5531fcd8..59f5c559a62a0e220a2688c06171faa01eb05196 100644 (file)
@@ -15,15 +15,12 @@ import static org.mockito.Mockito.mock;
 import com.google.common.base.Optional;
 import com.google.common.collect.Lists;
 import com.google.common.util.concurrent.ListenableFuture;
-
 import io.netty.util.HashedWheelTimer;
 import io.netty.util.Timer;
-
 import java.math.BigInteger;
+import java.util.Collections;
 import java.util.List;
-
 import junit.framework.Assert;
-
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -186,7 +183,7 @@ public class ProgrammingServiceImplTest {
     private void assertCleanInstructionOutput(ListenableFuture<RpcResult<CleanInstructionsOutput>> cleanedInstructionOutput,
             int unflushedCount) throws InterruptedException, java.util.concurrent.ExecutionException {
         if (unflushedCount == 0) {
-            Assert.assertNull(cleanedInstructionOutput.get().getResult().getUnflushed());
+            Assert.assertEquals(Collections.EMPTY_LIST, cleanedInstructionOutput.get().getResult().getUnflushed());
         } else {
             Assert.assertEquals(unflushedCount, cleanedInstructionOutput.get().getResult().getUnflushed().size());
         }