BUG-3129 NPE in flowHash
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / registry / flow / FlowHashFactory.java
index ea0feeddd1a0144f5d789c90a0e6ad930844d336..9eec7ea72342e8cafbbd0a6a87c02f0614c60ce0 100644 (file)
@@ -8,9 +8,12 @@
 
 package org.opendaylight.openflowplugin.impl.registry.flow;
 
+import com.google.common.base.MoreObjects;
+import com.google.common.base.Preconditions;
 import com.google.common.primitives.Longs;
 import java.math.BigInteger;
 import java.util.Objects;
+import org.opendaylight.openflowplugin.api.OFConstants;
 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
 import org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowHash;
 import org.opendaylight.openflowplugin.impl.util.HashUtil;
@@ -47,9 +50,9 @@ public class FlowHashFactory {
         public FlowHashDto(final long flowHash, final Flow flow) {
             this.flowHash = flowHash;
             this.intHashCode = Longs.hashCode(flowHash);
-            tableId = flow.getTableId();
-            priority = flow.getPriority();
-            cookie = flow.getCookie().getValue();
+            tableId = Preconditions.checkNotNull(flow.getTableId(), "flow tableId must not be null");
+            priority = Preconditions.checkNotNull(flow.getPriority(), "flow priority must not be null");
+            cookie = MoreObjects.firstNonNull(flow.getCookie(), OFConstants.DEFAULT_FLOW_COOKIE).getValue();
         }
 
 
@@ -83,17 +86,17 @@ public class FlowHashFactory {
 
         @Override
         public short getTableId() {
-            return 0;
+            return tableId;
         }
 
         @Override
         public int getPriority() {
-            return 0;
+            return priority;
         }
 
         @Override
         public BigInteger getCookie() {
-            return null;
+            return cookie;
         }
     }
 }