[YANGTOOLS-359] NoSuchElementException during java binding generation from yang model with choice in module body at top level Created: 06/Nov/14  Updated: 10/Apr/22  Resolved: 07/May/15

Status: Resolved
Project: yangtools
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug
Reporter: Peter Kajsa Assignee: Peter Kajsa
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Operating System: All
Platform: All


External issue ID: 2333

 Description   

BindingGeneratorImpl fails during java source code generation from yang model witch contains choice element directly in module body at top level.

For an example:
module choice-test {
yang-version 1;
namespace "uri:choice-test";
prefix tst;

revision 2014-10-07

{ description "Choice test."; }

choice my-choice {
case one {
leaf my-choice-leaf-one

{ type string; }

}
case two {
leaf my-choice-leaf-two

{ type int16; }

}
}
}

This is because the line 1213 and 1214 in BindingGeneratorImpl.java class:
final SchemaPath nodeSp = choiceNode.getPath();
final Object parentNode = findDataSchemaNode(schemaContext, nodeSp.getParent());

The parent path of choice element is empty (because parent is module) and therefore iterator.next() on the path fails.

Exception stack trace:
Unable to generate sources with org.opendaylight.yangtools.maven.sal.api.gen.plugin.CodeGeneratorImpl generator
java.util.NoSuchElementException
at com.google.common.collect.Iterators$1.next(Iterators.java:71)
at org.opendaylight.yangtools.yang.model.util.SchemaContextUtil.findNodeInSchemaContext(SchemaContextUtil.java:252)
at org.opendaylight.yangtools.yang.model.util.SchemaContextUtil.findDataSchemaNode(SchemaContextUtil.java:83)
at org.opendaylight.yangtools.sal.binding.generator.impl.BindingGeneratorImpl.generateTypesFromChoiceCases(BindingGeneratorImpl.java:1215)
at org.opendaylight.yangtools.sal.binding.generator.impl.BindingGeneratorImpl.choiceToGeneratedType(BindingGeneratorImpl.java:1161)
at org.opendaylight.yangtools.sal.binding.generator.impl.BindingGeneratorImpl.addSchemaNodeToBuilderAsMethod(BindingGeneratorImpl.java:1117)
at org.opendaylight.yangtools.sal.binding.generator.impl.BindingGeneratorImpl.resolveDataSchemaNodes(BindingGeneratorImpl.java:1046)
at org.opendaylight.yangtools.sal.binding.generator.impl.BindingGeneratorImpl.moduleToGenTypes(BindingGeneratorImpl.java:268)
at org.opendaylight.yangtools.sal.binding.generator.impl.BindingGeneratorImpl.generateTypes(BindingGeneratorImpl.java:237)
at org.opendaylight.yangtools.maven.sal.api.gen.plugin.CodeGeneratorImpl.generateSources(CodeGeneratorImpl.java:62)

....



 Comments   
Comment by Peter Kajsa [ 13/Nov/14 ]

fix: https://git.opendaylight.org/gerrit/#/c/12813/

Generated at Wed Feb 07 20:52:59 UTC 2024 using Jira 8.20.10#820010-sha1:ace47f9899e9ee25d7157d59aa17ab06aee30d3d.