From: Robert Varga Date: Mon, 19 Apr 2021 19:41:10 +0000 (+0200) Subject: Improve ImmutableAugmentationNodeBuilder defensiveness X-Git-Tag: v6.0.6~8 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=63e5382df42a1018ce79d5d4221819fc5ea2a5c4;hp=99d0a43d0f67ab0b98d56ac4a5b51cb7b1f76e80;p=yangtools.git Improve ImmutableAugmentationNodeBuilder defensiveness The check for nested augmentations is rather ugly and will trigger a secondary UnsupportedOperationException -- simply because we are accessing getNodeType() even for AugmentationNodes. Fix the thinko by performing an explicit check first, which also makes things a wee bit faster. Change-Id: I001c8d3b7c4a53ddb2c45d7c9157f7b1081dc992 Signed-off-by: Robert Varga (cherry picked from commit 1e24596294bdc2a57a808b77a2d9862198e4f46e) --- diff --git a/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/builder/impl/ImmutableAugmentationNodeBuilder.java b/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/builder/impl/ImmutableAugmentationNodeBuilder.java index 912cdc487a..0db20084b4 100644 --- a/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/builder/impl/ImmutableAugmentationNodeBuilder.java +++ b/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/builder/impl/ImmutableAugmentationNodeBuilder.java @@ -53,9 +53,12 @@ public class ImmutableAugmentationNodeBuilder public DataContainerNodeBuilder withChild( final DataContainerChild child) { // Check nested augments - DataValidationException.checkLegalData(!(child instanceof AugmentationNode), - "Unable to add: %s, as a child for: %s, Nested augmentations are not permitted", child.getNodeType(), - getNodeIdentifier() == null ? this : getNodeIdentifier()); + if (child instanceof AugmentationNode) { + final AugmentationIdentifier myId = getNodeIdentifier(); + throw new DataValidationException(String.format( + "Unable to add: %s, as a child for: %s, Nested augmentations are not permitted", child.getIdentifier(), + myId == null ? this : myId)); + } return super.withChild(child); }