- final int childrenAfter;
- if (modification.getWrittenValue() != null) {
- childrenAfter = numOfChildrenFromValue(modification.getWrittenValue());
- } else {
- childrenAfter = 0;
- }
+ 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);