[YANGTOOLS-796] Default of a union in YANG 1.1 only processed correctly if corresponds to first member type Created: 10/Jul/17  Updated: 10/Apr/22  Resolved: 07/Aug/17

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

Type: Bug
Reporter: Peter Verthez 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


Attachments: File example-model.yang     File example-model2.yang    
External issue ID: 8831

 Description   

When a leaf has a union type, and a default that does not correspond to the first member of that union type, the default is not processed correctly. The attached model gives an error:

Caused by: org.opendaylight.yangtools.yang.parser.spi.source.SourceException: Unable to find a default value for leaf '(http://www.example.com?revision=2017-07-10)enum-last-leaf' [at example-model:35:4]
at org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.LeafEffectiveStatementImpl.(LeafEffectiveStatementImpl.java:67)
at org.opendaylight.yangtools.yang.parser.stmt.rfc6020.LeafStatementImpl$Definition.createEffective(LeafStatementImpl.java:79)
at org.opendaylight.yangtools.yang.parser.stmt.reactor.StatementContextBase.buildEffective(StatementContextBase.java:408)
at com.google.common.collect.Iterators$8.transform(Iterators.java:799)
at com.google.common.collect.TransformedIterator.next(TransformedIterator.java:48)
at java.util.AbstractCollection.toArray(AbstractCollection.java:141)
at com.google.common.collect.ImmutableList.copyOf(ImmutableList.java:258)
at org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.EffectiveStatementBase.(EffectiveStatementBase.java:56)
at org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.DeclaredEffectiveStatementBase.(DeclaredEffectiveStatementBase.java:32)
at org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.AbstractEffectiveDocumentedNode.(AbstractEffectiveDocumentedNode.java:30)
at org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.AbstractEffectiveDocumentedDataNodeContainer.(AbstractEffectiveDocumentedDataNodeContainer.java:45)
at org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.AbstractEffectiveSimpleDataNodeContainer.(AbstractEffectiveSimpleDataNodeContainer.java:47)
at org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.AbstractEffectiveContainerSchemaNode.(AbstractEffectiveContainerSchemaNode.java:21)
at org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.ContainerEffectiveStatementImpl.(ContainerEffectiveStatementImpl.java:32)
at org.opendaylight.yangtools.yang.parser.stmt.rfc6020.ContainerStatementImpl$Definition.createEffective(ContainerStatementImpl.java:86)
at org.opendaylight.yangtools.yang.parser.stmt.reactor.StatementContextBase.buildEffective(StatementContextBase.java:408)
at com.google.common.collect.Iterators$8.transform(Iterators.java:799)
at com.google.common.collect.TransformedIterator.next(TransformedIterator.java:48)
at java.util.AbstractCollection.toArray(AbstractCollection.java:141)
at com.google.common.collect.ImmutableList.copyOf(ImmutableList.java:258)
at org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.EffectiveStatementBase.(EffectiveStatementBase.java:56)
at org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.DeclaredEffectiveStatementBase.(DeclaredEffectiveStatementBase.java:32)
at org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.AbstractEffectiveDocumentedNode.(AbstractEffectiveDocumentedNode.java:30)
at org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.AbstractEffectiveModule.(AbstractEffectiveModule.java:86)
at org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.ModuleEffectiveStatementImpl.(ModuleEffectiveStatementImpl.java:23)
at org.opendaylight.yangtools.yang.parser.stmt.rfc6020.ModuleStatementSupport.createEffective(ModuleStatementSupport.java:100)
at org.opendaylight.yangtools.yang.parser.stmt.reactor.StatementContextBase.buildEffective(StatementContextBase.java:408)
at org.opendaylight.yangtools.yang.parser.stmt.reactor.BuildGlobalContext.transformEffective(BuildGlobalContext.java:250)
... 80 more
Caused by: java.lang.IllegalStateException: Unable to find following default values [any]
at com.google.common.base.Preconditions.checkState(Preconditions.java:197)
at org.opendaylight.yangtools.yang.parser.stmt.rfc6020.TypeUtils.isAnyDefaultValueMarkedWithIfFeature(TypeUtils.java:305)
at org.opendaylight.yangtools.yang.parser.stmt.rfc6020.TypeUtils.isAnyDefaultValueMarkedWithIfFeature(TypeUtils.java:300)
at org.opendaylight.yangtools.yang.parser.stmt.rfc6020.TypeUtils.isAnyDefaultValueMarkedWithIfFeature(TypeUtils.java:300)
at org.opendaylight.yangtools.yang.parser.stmt.rfc6020.TypeUtils.hasDefaultValueMarkedWithIfFeature(TypeUtils.java:277)
at org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.LeafEffectiveStatementImpl.(LeafEffectiveStatementImpl.java:61)
... 107 more

This is because TypeUtils.isAnyDefaultValueMarkedWithIfFeature is called recursively, but bails out after the first member type of the union.



 Comments   
Comment by Peter Verthez [ 10/Jul/17 ]

Attachment example-model.yang has been added with description: Model to trigger the bug

Comment by Peter Verthez [ 11/Jul/17 ]

That doesn't seem to be the only case where there are problems with defaults: also the model in example-model2.yang (attached) has a problem. There the default is a number, which is in the range of the first member of the union.

Comment by Peter Verthez [ 11/Jul/17 ]

Attachment example-model2.yang has been added with description: Second case

Comment by Peter Kajsa [ 04/Aug/17 ]

https://git.opendaylight.org/gerrit/#/c/61170/

Comment by Robert Varga [ 05/Aug/17 ]

carbon: https://git.opendaylight.org/gerrit/61222

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