Merge "Bug 7916: MatchConvertorImpl detailed IllegalStateException instead NPE"
authorAbhijit Kumbhare <abhijit.kumbhare@ericsson.com>
Wed, 15 Mar 2017 22:14:34 +0000 (22:14 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Wed, 15 Mar 2017 22:14:34 +0000 (22:14 +0000)
.gitignore
extension/openflowplugin-extension-api/src/main/java/org/opendaylight/openflowplugin/extension/api/ConverterExtensionKey.java
extension/openflowplugin-extension-api/src/main/java/org/opendaylight/openflowplugin/extension/api/TypeVersionKey.java
openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/match/MatchConvertorImpl.java

index 622f0ffc0ff13212506e774a0f3173b23f5fdb74..4d961c1591cbe0d9ae9e0fa66fed662d2bf9fed8 100644 (file)
@@ -1,5 +1,6 @@
 .idea/
 target/
+target-ide/
 *.class
 *.iml
 **/target
@@ -10,7 +11,6 @@ products
 repository
 workspace
 *~
-target
 .classpath
 .project
 .settings
index 7c898e7d56194735b9fb8a5d039a6e392b8b4859..5be272a935ecb364d4158725f6a215fb57a67fa4 100644 (file)
@@ -1,6 +1,6 @@
 /**
  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
- * 
+ *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
@@ -12,14 +12,11 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.ge
 /**
  * lookup and register key for extension converters, basic case expects this to
  * correlate with input model type
- * 
+ *
  * @param <T> type of key
  */
 public class ConverterExtensionKey<T extends ExtensionKey> extends TypeVersionKey<T> {
 
-    /**
-     * @param type
-     */
     public ConverterExtensionKey(Class<T> type, short ofVersion) {
         super(type, ofVersion);
     }
index 86b657471d0c8dd4c9215c38e846497733212d11..5f602b3dab495cb03214e4c1ded7c2596d3f7452 100644 (file)
@@ -1,6 +1,6 @@
 /**
  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
- * 
+ *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
@@ -11,18 +11,14 @@ package org.opendaylight.openflowplugin.extension.api;
 /**
  * lookup and register key for extension converters, basic case expects this to
  * correlate with input model type
- * 
+ *
  * @param <T> type of key
  */
 public class TypeVersionKey<T> {
 
-    private Class<? extends T> type;
-    private short ofVersion;
+    private final Class<? extends T> type;
+    private final short ofVersion;
 
-    /**
-     * @param type
-     * @param ofVersion 
-     */
     public TypeVersionKey(Class<? extends T> type, short ofVersion) {
         this.type = type;
         this.ofVersion = ofVersion;
@@ -40,7 +36,7 @@ public class TypeVersionKey<T> {
         final int prime = 31;
         int result = 1;
         result = prime * result + ofVersion;
-        result = prime * result + ((type == null) ? 0 : type.hashCode());
+        result = prime * result + (type == null ? 0 : type.hashCode());
         return result;
     }
 
@@ -60,11 +56,18 @@ public class TypeVersionKey<T> {
             return false;
         }
         if (type == null) {
-            if (other.type != null)
+            if (other.type != null) {
                 return false;
-        } else if (!type.equals(other.type))
+            }
+        } else if (!type.equals(other.type)) {
             return false;
+        }
         return true;
     }
 
+    @Override
+    public String toString() {
+        return getClass().getSimpleName() + " [type=" + type + ", ofVersion=" + ofVersion + "]";
+    }
+
 }
index bd6891602691936fc3eac8b4a934706bf1ca1917..56c7d5056248f797a4c98bbdf4c118837d939983 100644 (file)
@@ -332,7 +332,7 @@ public class MatchConvertorImpl implements MatchConvertor<List<MatchEntry>> {
                     vidEntryValue = vlanId.getVlanId().getValue();
                 }
 
-                hasmask = (vidEntryValue == 0);
+                hasmask = vidEntryValue == 0;
                 if (hasmask) {
                     vlanVidBuilder.setMask(VLAN_VID_MASK);
                 }
@@ -604,14 +604,17 @@ public class MatchConvertorImpl implements MatchConvertor<List<MatchEntry>> {
         /**
          * TODO: EXTENSION PROPOSAL (match, MD-SAL to OFJava)
          * - we might need version for conversion and for key
-         * - sanitize NPE
          */
         Optional<GeneralExtensionListGrouping> extensionListOpt = ExtensionResolvers.getMatchExtensionResolver().getExtension(match);
         if (extensionListOpt.isPresent()) {
-            for (ExtensionList extensionItem : extensionListOpt.get().getExtensionList()) {
+            List<ExtensionList> extensionListList = extensionListOpt.get().getExtensionList();
+            for (ExtensionList extensionItem : extensionListList) {
                 // TODO: get real version
                 ConverterExtensionKey<? extends ExtensionKey> key = new ConverterExtensionKey<>(extensionItem.getExtensionKey(), OFConstants.OFP_VERSION_1_3);
                 ConvertorToOFJava<MatchEntry> convertor = OFSessionUtil.getExtensionConvertorProvider().getConverter(key);
+                if (convertor == null) {
+                    throw new IllegalStateException("No converter found for key: " + key.toString());
+                }
                 MatchEntry ofMatch = convertor.convert(extensionItem.getExtension());
                 result.add(ofMatch);
             }