Improve list key presence checks 43/88843/1
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 31 Mar 2020 13:21:03 +0000 (15:21 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Thu, 2 Apr 2020 08:18:09 +0000 (10:18 +0200)
A few statements are explicitly not part of instantiated tree, but
rather define a different data tree instance, which may be related
the instantiated tree.

We checked only for groupings, but we need to also consider input,
output and notification statements.

JIRA: YANGTOOLS-1090
Change-Id: I8f497ec2998b74388924d62c5dbef2b204ecefab
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
(cherry picked from commit db7730134c0976be33585fd2bbfe899f9a1163a1)

yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/list/AbstractListStatementSupport.java

index 6dd8848bc90e65b818342c72d3708c5eb74e7fe4..3a1ec687587e1d05437e3684a3e5189a434a2253 100644 (file)
@@ -8,6 +8,7 @@
 package org.opendaylight.yangtools.yang.parser.rfc7950.stmt.list;
 
 import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
 import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.List;
@@ -42,6 +43,8 @@ import org.slf4j.LoggerFactory;
 
 abstract class AbstractListStatementSupport extends BaseQNameStatementSupport<ListStatement, ListEffectiveStatement> {
     private static final Logger LOG = LoggerFactory.getLogger(AbstractListStatementSupport.class);
+    private static final ImmutableSet<YangStmtMapping> UNINSTANTIATED_DATATREE_STATEMENTS = ImmutableSet.of(
+        YangStmtMapping.GROUPING, YangStmtMapping.NOTIFICATION, YangStmtMapping.INPUT, YangStmtMapping.OUTPUT);
 
     AbstractListStatementSupport() {
         super(YangStmtMapping.LIST);
@@ -110,7 +113,7 @@ abstract class AbstractListStatementSupport extends BaseQNameStatementSupport<Li
                 .setUserOrdered(findFirstArgument(substatements, OrderedByEffectiveStatement.class, "system")
                     .equals("user"))
                 .toFlags();
-        if (configuration && keyDefinition.isEmpty() && !inGrouping(ctx)) {
+        if (configuration && keyDefinition.isEmpty() && isInstantied(ctx)) {
             LOG.info("Configuration list {} does not define any keys in violation of RFC7950 section 7.8.2. While "
                     + " this is fine with OpenDaylight, it can cause interoperability issues with other systems "
                     + "[at {}]", ctx.getStatementArgument(), ref);
@@ -124,15 +127,13 @@ abstract class AbstractListStatementSupport extends BaseQNameStatementSupport<Li
                             elementCountConstraint.orElse(null), original);
     }
 
-    private static boolean inGrouping(final StmtContext<?, ?, ?> ctx) {
-        StmtContext<?, ?, ?> parent = ctx.getParentContext();
-        while (parent != null) {
-            if (parent.getPublicDefinition() == YangStmtMapping.GROUPING) {
-                return true;
+    private static boolean isInstantied(final StmtContext<?, ?, ?> ctx) {
+        for (StmtContext<?, ?, ?> parent = ctx.getParentContext(); parent != null; parent = parent.getParentContext()) {
+            if (UNINSTANTIATED_DATATREE_STATEMENTS.contains(parent.getPublicDefinition())) {
+                return false;
             }
-            parent = parent.getParentContext();
         }
-        return false;
+        return true;
     }
 
     @Override