Improve ImmutableAugmentationNodeBuilder defensiveness
[yangtools.git] / yang / yang-data-impl / src / main / java / org / opendaylight / yangtools / yang / data / impl / schema / builder / impl / ImmutableAugmentationNodeBuilder.java
index 23871b4b560c6de3cc93f9cb8689fb3fa3b680f7..e445f42fb630f23e68a66ba5ed5d44c4678c2acc 100644 (file)
@@ -53,9 +53,12 @@ public class ImmutableAugmentationNodeBuilder
     public DataContainerNodeBuilder<AugmentationIdentifier, AugmentationNode> 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);
     }