From: Robert Varga Date: Thu, 26 Nov 2015 13:42:58 +0000 (+0100) Subject: BUG-4684: Add strict internal consistency checks for min/max X-Git-Tag: release/beryllium~110 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F47%2F30247%2F3;hp=27e94a9b44c9394e1d679031777021fc2ebfb6ee;p=yangtools.git BUG-4684: Add strict internal consistency checks for min/max 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 --- diff --git a/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/MinMaxElementsValidation.java b/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/MinMaxElementsValidation.java index ab0afcf9f4..932f20a810 100644 --- a/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/MinMaxElementsValidation.java +++ b/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/MinMaxElementsValidation.java @@ -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(),