From 1e24596294bdc2a57a808b77a2d9862198e4f46e Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Mon, 19 Apr 2021 21:41:10 +0200 Subject: [PATCH] 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 --- .../builder/impl/ImmutableAugmentationNodeBuilder.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) 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 23871b4b56..e445f42fb6 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); } -- 2.36.6