From 5fe7fc9a85cd5579433cf5366ebee72ce3ff9f43 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Tue, 15 Feb 2022 22:57:15 +0100 Subject: [PATCH] Verify exclusion consistency SpotBugs warns on null here, make sure to add verifyNotNull(). Also used import static for Verify and Preconditions methods. Change-Id: I807ab197b60d8df2cd8a95541f83cbef8020661b Signed-off-by: Robert Varga --- .../tree/impl/ChoiceModificationStrategy.java | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/data/yang-data-tree-ri/src/main/java/org/opendaylight/yangtools/yang/data/tree/impl/ChoiceModificationStrategy.java b/data/yang-data-tree-ri/src/main/java/org/opendaylight/yangtools/yang/data/tree/impl/ChoiceModificationStrategy.java index d141d38444..7de1029c4f 100644 --- a/data/yang-data-tree-ri/src/main/java/org/opendaylight/yangtools/yang/data/tree/impl/ChoiceModificationStrategy.java +++ b/data/yang-data-tree-ri/src/main/java/org/opendaylight/yangtools/yang/data/tree/impl/ChoiceModificationStrategy.java @@ -7,9 +7,11 @@ */ package org.opendaylight.yangtools.yang.data.tree.impl; -import com.google.common.base.Preconditions; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Verify.verify; +import static com.google.common.base.Verify.verifyNotNull; + import com.google.common.base.Predicates; -import com.google.common.base.Verify; import com.google.common.collect.Collections2; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; @@ -115,20 +117,19 @@ final class ChoiceModificationStrategy extends Visible { } private void enforceCases(final NormalizedNode normalizedNode) { - Verify.verify(normalizedNode instanceof ChoiceNode); - final Collection children = ((ChoiceNode) normalizedNode).body(); + verify(normalizedNode instanceof ChoiceNode); + final var children = ((ChoiceNode) normalizedNode).body(); if (!children.isEmpty()) { final DataContainerChild firstChild = children.iterator().next(); - final CaseEnforcer enforcer = Verify.verifyNotNull(caseEnforcers.get(firstChild.getIdentifier()), + final CaseEnforcer enforcer = verifyNotNull(caseEnforcers.get(firstChild.getIdentifier()), "Case enforcer cannot be null. Most probably, child node %s of choice node %s does not belong " + "in current tree type.", firstChild.getIdentifier(), normalizedNode.getIdentifier()); // Make sure no leaves from other cases are present - for (final CaseEnforcer other : exclusions.get(enforcer)) { + for (final CaseEnforcer other : verifyNotNull(exclusions.get(enforcer))) { for (final PathArgument id : other.getAllChildIdentifiers()) { - final Optional maybeChild = NormalizedNodes.getDirectChild(normalizedNode, - id); - Preconditions.checkArgument(!maybeChild.isPresent(), + final Optional maybeChild = NormalizedNodes.getDirectChild(normalizedNode, id); + checkArgument(!maybeChild.isPresent(), "Child %s (from case %s) implies non-presence of child %s (from case %s), which is %s", firstChild.getIdentifier(), enforcer, id, other, maybeChild.orElse(null)); } -- 2.36.6