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 <robert.varga@pantheon.tech>
public DataContainerNodeBuilder<AugmentationIdentifier, AugmentationNode> withChild(
final DataContainerChild child) {
// Check nested augments
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);
}
return super.withChild(child);
}