[MDSAL-505] Improve leafref cycle detection Created: 23/Dec/19  Updated: 19/Jan/24

Status: In Review
Project: mdsal
Component/s: Binding codegen
Affects Version/s: None
Fix Version/s: 13.0.1

Type: Improvement Priority: Medium
Reporter: Robert Varga Assignee: Samuel Schneider
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

Current detection of circular leafref chains relies on parsing the expression multiple times and attempting to detect when we arrive at the same leafref.

We should be able to improve this by tracking which leafref leaf nodes we have traversed, using a simple Collection.contains() to check we re-encountering a leafref.



 Comments   
Comment by Samuel Schneider [ 19/Jun/23 ]

rovarga
I was looking in to this and I couldn't find any circular leafref chains detection. Only check for self-referencing leaf.
Is something like this meant to be circular leafref chain?:

    list neighbor {
         description
           "List of neighbors.";
         leaf neighbor-id1 {
             type leafref {
                 path "../../neighbor/neighbor-id2";
             }
             description "Neighbor.";
         }

         leaf neighbor-id2 {
             type leafref {
                  path "../../neighbor/neighbor-id3";
             }
             description "Neighbor.";
         }

         leaf neighbor-id3 {
             type leafref {
                 path "../../neighbor/neighbor-id1";
             }
            description "Neighbor.";
         }
    }

if so, attempt to generate from yang like this results in StackOverflowError.

Caused by: java.lang.StackOverflowError
        at org.opendaylight.mdsal.binding.generator@12.0.0-SNAPSHOT/org.opendaylight.mdsal.binding.generator.impl.reactor.AbstractTypeObjectGenerator.methodReturnElementType(AbstractTypeObjectGenerator.java)
        at org.opendaylight.mdsal.binding.generator@12.0.0-SNAPSHOT/org.opendaylight.mdsal.binding.generator.impl.reactor.TypeReference$ResolvedLeafref.methodReturnType(TypeReference.java:61)
        at org.opendaylight.mdsal.binding.generator@12.0.0-SNAPSHOT/org.opendaylight.mdsal.binding.generator.impl.reactor.AbstractTypeObjectGenerator.createMethodReturnElementType(AbstractTypeObjectGenerator.java:499)
        at org.opendaylight.mdsal.binding.generator@12.0.0-SNAPSHOT/org.opendaylight.mdsal.binding.generator.impl.reactor.AbstractTypeObjectGenerator.methodReturnElementType(AbstractTypeObjectGenerator.java:485)
        at org.opendaylight.mdsal.binding.generator@12.0.0-SNAPSHOT/org.opendaylight.mdsal.binding.generator.impl.reactor.TypeReference$ResolvedLeafref.methodReturnType(TypeReference.java:61)
        at org.opendaylight.mdsal.binding.generator@12.0.0-SNAPSHOT/org.opendaylight.mdsal.binding.generator.impl.reactor.AbstractTypeObjectGenerator.createMethodReturnElementType(AbstractTypeObjectGenerator.java:499)
        at org.opendaylight.mdsal.binding.generator@12.0.0-SNAPSHOT/org.opendaylight.mdsal.binding.generator.impl.reactor.AbstractTypeObjectGenerator.methodReturnElementType(AbstractTypeObjectGenerator.java:485)
        at org.opendaylight.mdsal.binding.generator@12.0.0-SNAPSHOT/org.opendaylight.mdsal.binding.generator.impl.reactor.TypeReference$ResolvedLeafref.methodReturnType(TypeReference.java:61)
Generated at Wed Feb 07 20:09:58 UTC 2024 using Jira 8.20.10#820010-sha1:ace47f9899e9ee25d7157d59aa17ab06aee30d3d.