[YANGTOOLS-885] SchemaContextUtil.findDataSchemaNode(RevisionAwareXPath) does not work correctly Created: 05/Jun/18  Updated: 08/Jun/18  Resolved: 08/Jun/18

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

Type: Bug Priority: High
Reporter: Anna Bencúrová Assignee: Robert Varga
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: File test-model-not-compilable.yang     File test-model.yang    

 Description   

The leafref path should be according RFC 6020:
The syntax for a path argument is a subset of the XPath abbreviated syntax.
XML doesn't contain choice and case entries, so the XPath probably should not contain them also. I am attaching two yang files. One is compilable (test-model.yang), where are two leafs with leafref type. They have included name of the choice and case in the path string. In the other file (test-model-not-compilable.yang), leafref path doesn't contain choice and case name and this is not compilable.



 Comments   
Comment by Robert Varga [ 05/Jun/18 ]

Codegen fails with:

[ERROR] yang-to-sources: Unable to generate sources with org.opendaylight.mdsal.binding.maven.api.gen.plugin.CodeGeneratorImpl generator
java.lang.IllegalArgumentException: Failed to find leafref target: /container-name/case-augment-container-name/case-augment-leaf-name in module test-model (QNameModule{ns=urn:test-model, rev=2018-06-05})
    at com.google.common.base.Preconditions.checkArgument (Preconditions.java:455)
    at org.opendaylight.mdsal.binding.yang.types.AbstractTypeProvider.provideTypeForLeafref (AbstractTypeProvider.java:552)
    at org.opendaylight.mdsal.binding.yang.types.AbstractTypeProvider.javaTypeForLeafrefOrIdentityRef (AbstractTypeProvider.java:318)
    at org.opendaylight.mdsal.binding.yang.types.AbstractTypeProvider.javaTypeForSchemaDefinitionType (AbstractTypeProvider.java:212)
    at org.opendaylight.mdsal.binding.generator.impl.AbstractTypeGenerator.resolveLeafSchemaNodeAsMethod (AbstractTypeGenerator.java:1366)
    at org.opendaylight.mdsal.binding.generator.impl.AbstractTypeGenerator.addSchemaNodeToBuilderAsMethod (AbstractTypeGenerator.java:1063)
    at org.opendaylight.mdsal.binding.generator.impl.AbstractTypeGenerator.resolveDataSchemaNodes (AbstractTypeGenerator.java:1000)
    at org.opendaylight.mdsal.binding.generator.impl.AbstractTypeGenerator.containerToGenType (AbstractTypeGenerator.java:276)
    at org.opendaylight.mdsal.binding.generator.impl.AbstractTypeGenerator.addSchemaNodeToBuilderAsMethod (AbstractTypeGenerator.java:1067)
    at org.opendaylight.mdsal.binding.generator.impl.AbstractTypeGenerator.resolveDataSchemaNodes (AbstractTypeGenerator.java:1000)
    at org.opendaylight.mdsal.binding.generator.impl.AbstractTypeGenerator.moduleToGenTypes (AbstractTypeGenerator.java:213)
    at org.opendaylight.mdsal.binding.generator.impl.AbstractTypeGenerator.<init> (AbstractTypeGenerator.java:173)
    at org.opendaylight.mdsal.binding.generator.impl.CodegenTypeGenerator.<init> (CodegenTypeGenerator.java:30)
    at org.opendaylight.mdsal.binding.generator.impl.BindingGeneratorImpl.generateTypes (BindingGeneratorImpl.java:55)
    at org.opendaylight.mdsal.binding.maven.api.gen.plugin.CodeGeneratorImpl.generateSources (CodeGeneratorImpl.java:61)
    at org.opendaylight.yangtools.yang2sources.plugin.YangToSourcesProcessor.generateSourcesWithOneGenerator (YangToSourcesProcessor.java:379)
    at org.opendaylight.yangtools.yang2sources.plugin.YangToSourcesProcessor.generateSources (YangToSourcesProcessor.java:329)
    at org.opendaylight.yangtools.yang2sources.plugin.YangToSourcesProcessor.conditionalExecute (YangToSourcesProcessor.java:156)
    at org.opendaylight.yangtools.yang2sources.plugin.YangToSourcesMojo.execute (YangToSourcesMojo.java:123)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:134)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:208)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:154)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:146)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:51)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:309)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:194)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:107)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:955)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:290)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:194)
    at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:498)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:356)
Comment by Robert Varga [ 05/Jun/18 ]

XPaths do not work with choice/case statements, i.e. they ignore them and move to the closest ancestor data node. While the stack trace does not show anything yangtools, the actual logic to resolve these lives in yang.model.util.SchemaContextUtil, hence it needs to be fixed there.

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