Add field type check 55/35455/2
authorRobert Varga <rovarga@cisco.com>
Fri, 26 Feb 2016 10:22:22 +0000 (11:22 +0100)
committerGerrit Code Review <gerrit@opendaylight.org>
Fri, 26 Feb 2016 11:34:02 +0000 (11:34 +0000)
Eagerly check if the field being accessed is in fact a Map, so we
prevent ClassCast exceptions.

Change-Id: I59322cbde9dfc6df8ab122b71e77644f64d5e302
Signed-off-by: Robert Varga <rovarga@cisco.com>
binding/yang-binding/src/main/java/org/opendaylight/yangtools/yang/binding/util/AugmentationFieldGetter.java

index c1cf7f905780b1942a99af7c70f8d244e402e789..03c04c4c7a231436f2a28fbb6c7d6b5fa2c35ed1 100644 (file)
@@ -78,6 +78,11 @@ abstract class AugmentationFieldGetter {
                     BindingMapping.AUGMENTATION_FIELD, key, e);
                 return DUMMY;
             }
+            if (!Map.class.isAssignableFrom(field.getType())) {
+                LOG.warn("Class {} field {} is not a Map, ignoring augmentations", key,
+                    BindingMapping.AUGMENTATION_FIELD);
+                return DUMMY;
+            }
 
             return new ReflectionAugmentationFieldGetter(LOOKUP.unreflectGetter(field).asType(GETTER_TYPE));
         }