Use modifiable List when resolving relative xpath 33/91333/1
authorTomas Cere <tomas.cere@pantheon.tech>
Tue, 14 Jul 2020 13:05:18 +0000 (15:05 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 15 Jul 2020 10:04:13 +0000 (12:04 +0200)
When we have split the path into its components, we can end up
compressing them further. Make sure the list is actually mutable.

JIRA: YANGTOOLS-1125
Change-Id: I1d4cd66d2efbb1955bb189763ea09fefeba93d25
Signed-off-by: Tomas Cere <tomas.cere@pantheon.tech>
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
(cherry picked from commit 69cb7d1ab7a329e2bd19f538b3d598be91c49f2d)

yang/yang-model-util-ut/src/test/java/org/opendaylight/yangtools/yang/model/util/ut/LeafrefStaticAnalysisTest.java
yang/yang-model-util-ut/src/test/resources/leafrefs.yang
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/SchemaContextUtil.java

index 22bcc32e15b9999a516fe29becad11e404cd0465..93bba0d578e54ea6bdef8605f3038e10ccf7507a 100644 (file)
@@ -135,4 +135,12 @@ public class LeafrefStaticAnalysisTest {
         assertNull(SchemaContextUtil.findDataSchemaNodeForRelativeXPath(context, module, leaf,
             ((LeafrefTypeDefinition) leaf.getType()).getPathStatement()));
     }
+
+    @Test
+    public void testNonExistentRelativeXpath() {
+        final LeafSchemaNode leaf = (LeafSchemaNode) bar.findDataChildByName(
+                QName.create(FOO, "indirect-with-current")).get();
+        assertNull(SchemaContextUtil.findDataSchemaNodeForRelativeXPath(context, module, leaf,
+                ((LeafrefTypeDefinition) leaf.getType()).getPathStatement()));
+    }
 }
index c923c589a86dc521a2bd2a2948763ea92c8f2b4e..925af6b3aad69f4478a8b913c391c28bc347414f 100644 (file)
@@ -29,6 +29,12 @@ module leafrefs {
       }
     }
 
+    leaf indirect-with-current {
+      type leafref {
+        path "../../../n[n-id=current()/../node]/tp/tp-id";
+      }
+    }
+
     leaf absolute {
       type leafref {
         // direct path to an instantiation
index e2006446dc02be088493d6aeacb561d8b57eb4da..a05e07602b66caf3f072ea594766ec5b05c2ca25 100644 (file)
@@ -836,7 +836,11 @@ public final class SchemaContextUtil {
     }
 
     private static List<String> doSplitXPath(final String xpath) {
-        return SLASH_SPLITTER.splitToList(xpath);
+        final List<String> ret = new ArrayList<>();
+        for (String str : SLASH_SPLITTER.split(xpath)) {
+            ret.add(str);
+        }
+        return ret;
     }
 
     /**