Move checkNotSealed() to addBuilder() 51/81251/2
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 28 Mar 2019 10:22:55 +0000 (11:22 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Thu, 28 Mar 2019 11:02:32 +0000 (12:02 +0100)
addBuilder() is called after previous check for seal from all callers,
who do not have any side-effects aside allocating arguments to
addBuilder().

Move the call to checkNotSealed() to addBuilder(), making the code
more straightforward and possibly preventing bugs from creeping in.

JIRA: CONTROLLER-1887
Change-Id: I127385378957deb7f38f1203870a0e52cd630644
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/transformer/NormalizedNodePruner.java

index 64dbc18..2082654 100644 (file)
@@ -75,13 +75,11 @@ public class NormalizedNodePruner implements NormalizedNodeStreamWriter {
 
     @Override
     public void startLeafSet(final NodeIdentifier nodeIdentifier, final int count) {
-        checkNotSealed();
         addBuilder(Builders.leafSetBuilder().withNodeIdentifier(nodeIdentifier), nodeIdentifier);
     }
 
     @Override
     public void startOrderedLeafSet(final NodeIdentifier nodeIdentifier, final int str) {
-        checkNotSealed();
         addBuilder(Builders.orderedLeafSetBuilder().withNodeIdentifier(nodeIdentifier), nodeIdentifier);
     }
 
@@ -111,7 +109,6 @@ public class NormalizedNodePruner implements NormalizedNodeStreamWriter {
 
     @Override
     public void startContainerNode(final NodeIdentifier nodeIdentifier, final int count) {
-        checkNotSealed();
         addBuilder(Builders.containerBuilder().withNodeIdentifier(nodeIdentifier), nodeIdentifier);
     }
 
@@ -122,44 +119,37 @@ public class NormalizedNodePruner implements NormalizedNodeStreamWriter {
 
     @Override
     public void startUnkeyedList(final NodeIdentifier nodeIdentifier, final int count) {
-        checkNotSealed();
         addBuilder(Builders.unkeyedListBuilder().withNodeIdentifier(nodeIdentifier), nodeIdentifier);
     }
 
     @Override
     public void startUnkeyedListItem(final NodeIdentifier nodeIdentifier, final int count) {
-        checkNotSealed();
         addBuilder(Builders.unkeyedListEntryBuilder().withNodeIdentifier(nodeIdentifier), nodeIdentifier);
     }
 
     @Override
     public void startMapNode(final NodeIdentifier nodeIdentifier, final int count) {
-        checkNotSealed();
         addBuilder(Builders.mapBuilder().withNodeIdentifier(nodeIdentifier), nodeIdentifier);
     }
 
     @Override
     public void startMapEntryNode(final NodeIdentifierWithPredicates nodeIdentifierWithPredicates, final int count) {
-        checkNotSealed();
         addBuilder(Builders.mapEntryBuilder().withNodeIdentifier(nodeIdentifierWithPredicates),
                 nodeIdentifierWithPredicates);
     }
 
     @Override
     public void startOrderedMapNode(final NodeIdentifier nodeIdentifier, final int count) {
-        checkNotSealed();
         addBuilder(Builders.orderedMapBuilder().withNodeIdentifier(nodeIdentifier), nodeIdentifier);
     }
 
     @Override
     public void startChoiceNode(final NodeIdentifier nodeIdentifier, final int count) {
-        checkNotSealed();
         addBuilder(Builders.choiceBuilder().withNodeIdentifier(nodeIdentifier), nodeIdentifier);
     }
 
     @Override
     public void startAugmentationNode(final AugmentationIdentifier augmentationIdentifier) {
-        checkNotSealed();
         addBuilder(Builders.augmentationBuilder().withNodeIdentifier(augmentationIdentifier), augmentationIdentifier);
     }
 
@@ -242,6 +232,8 @@ public class NormalizedNodePruner implements NormalizedNodeStreamWriter {
 
     private NormalizedNodeBuilderWrapper addBuilder(final NormalizedNodeContainerBuilder<?, ?, ?, ?> builder,
             final PathArgument identifier) {
+        checkNotSealed();
+
         final DataSchemaContextNode<?> schemaNode;
         final NormalizedNodeBuilderWrapper parent = stack.peek();
         if (parent != null) {

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.