Bug 2271: Fixed potentional NPE in generateTypesFromChoiceCases 85/12485/1
authorLukas Sedlak <lsedlak@cisco.com>
Tue, 21 Oct 2014 14:17:35 +0000 (16:17 +0200)
committerTony Tkacik <ttkacik@cisco.com>
Tue, 4 Nov 2014 09:40:36 +0000 (10:40 +0100)
Added check to verify if parent is not null since not
all GeneratedTypes can implement ChildOf<parent>
definition.

Change-Id: I9b01dc154fa767e2411c563540135051c3aab678
Signed-off-by: Lukas Sedlak <lsedlak@cisco.com>
(cherry picked from commit e296c756501bc50b1295a84a6ddd085850a71e32)

code-generator/binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/generator/impl/BindingGeneratorImpl.java

index 69bdebf49e7d7ad7d068c0dbf3bfe78928bc6edc..2fdfb2ad1d3bb00e395beb41905b770311772efd 100644 (file)
@@ -1208,9 +1208,8 @@ public class BindingGeneratorImpl implements BindingGenerator {
                 genCtx.get(module).addChoiceToCaseMapping(refChoiceType, caseTypeBuilder, caseNode);
                 final Iterable<DataSchemaNode> caseChildNodes = caseNode.getChildNodes();
                 if (caseChildNodes != null) {
-                    Object parentNode = null;
                     final SchemaPath nodeSp = choiceNode.getPath();
-                    parentNode = findDataSchemaNode(schemaContext, nodeSp.getParent());
+                    final Object parentNode = findDataSchemaNode(schemaContext, nodeSp.getParent());
 
                     SchemaNode parent;
                     if (parentNode instanceof AugmentationSchema) {
@@ -1233,14 +1232,15 @@ public class BindingGeneratorImpl implements BindingGenerator {
                         final SchemaPath sp = choiceNode.getPath();
                         parent = findDataSchemaNode(schemaContext, sp.getParent());
                     }
-                    GeneratedTypeBuilder childOfType = findChildNodeByPath(parent.getPath());
-                    if (childOfType == null) {
-                        childOfType = findGroupingByPath(parent.getPath());
+                    if (parent != null) {
+                        GeneratedTypeBuilder childOfType = findChildNodeByPath(parent.getPath());
+                        if (childOfType == null) {
+                            childOfType = findGroupingByPath(parent.getPath());
+                        }
+                        resolveDataSchemaNodes(module, basePackageName, caseTypeBuilder, childOfType, caseChildNodes);
                     }
-                    resolveDataSchemaNodes(module, basePackageName, caseTypeBuilder, childOfType, caseChildNodes);
                 }
             }
-
             processUsesAugments(caseNode, module);
         }
     }