BUG-4684: Add strict internal consistency checks for min/max 47/30247/3
authorRobert Varga <rovarga@cisco.com>
Thu, 26 Nov 2015 13:42:58 +0000 (14:42 +0100)
committerGerrit Code Review <gerrit@opendaylight.org>
Mon, 30 Nov 2015 15:28:49 +0000 (15:28 +0000)
We are still seeing problems with validation. Add debugs and Verify
checks to catch negative values. This will dump current and modification
state should we encounter a negative value for current nodes.

Change-Id: I3ab46a8f9d1442f5ad4f50ae8bb6d2bc17525d9b
Signed-off-by: Robert Varga <rovarga@cisco.com>
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/MinMaxElementsValidation.java

index ab0afcf9f4d1a929e7890945ffae5af6fce27f6c..932f20a810092d5d9543a5cabb94ebe0446deaf9 100644 (file)
@@ -11,6 +11,7 @@ package org.opendaylight.yangtools.yang.data.impl.schema.tree;
 
 import com.google.common.base.Optional;
 import com.google.common.base.Preconditions;
+import com.google.common.base.Verify;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
@@ -69,14 +70,21 @@ final class MinMaxElementsValidation extends SchemaAwareApplyOperation {
             LOG.debug("Could not validate {}, does not implement expected class {}", nodeMod, ModifiedNode.class);
             return;
         }
-        final ModifiedNode modification = (ModifiedNode) nodeMod;
 
+        final ModifiedNode modification = (ModifiedNode) nodeMod;
         final int childrenBefore = (modification.getOperation() == LogicalOperation.WRITE) ? 0 : findChildrenBefore
                 (current);
+        Verify.verify(childrenBefore >= 0, "Child count before is %s (from %s)", childrenBefore, current);
 
         final int childrenAfter = findChildrenAfter(modification);
+        Verify.verify(childrenAfter >= 0, "Child count after is %s (from %s)", childrenAfter, modification);
+
+        final int childrenModified = numOfChildrenFromChildMods(modification, current);
+        LOG.debug("Modified child count is %s (from %s and %s)", childrenModified, modification, current);
+
+        final int childrenTotal = childrenBefore + childrenAfter + childrenModified;
+        Verify.verify(childrenTotal >= 0, "Total child count is %s (from %s and %s)", childrenTotal, modification, current);
 
-        final int childrenTotal = childrenBefore + childrenAfter + numOfChildrenFromChildMods(modification, current);
         if (minElements != null && minElements > childrenTotal) {
             throw new DataValidationFailedException(path, String.format(
                     "%s does not have enough elements (%s), needs at least %s", modification.getIdentifier(),