Fix NONE operation node with automatic lifecycle 27/81427/1
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 8 Apr 2019 01:15:57 +0000 (03:15 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 8 Apr 2019 01:17:07 +0000 (03:17 +0200)
In case when previous operations fizzle into a NONE operation
on top of a non-present node, automatic lifecycle would fail
because there is no node to disappear.

Fix this case by not requiring the delegate operation to return
a present node.

JIRA: YANGTOOLS-938
Change-Id: I6b4a01af61e148efa0bae3953dd5aa80b2e63398
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
(cherry picked from commit 1f36b5e960a68f80d8dcf0d3f259f22f74bf2495)

yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/StructuralContainerModificationStrategy.java

index 4d3f22d58dc71a9510af5376a23e36d7c6044abc..ce735c009c3ee26d3e2dbaef2dccd683a069235d 100644 (file)
@@ -63,21 +63,21 @@ final class StructuralContainerModificationStrategy extends DelegatingModificati
         // The only way a tree node can disappear is through delete (which we handle here explicitly) or through
         // actions of disappearResult(). It is therefore safe to perform Optional.get() on the results of
         // delegate.apply()
-        final TreeNode ret;
+        final Optional<TreeNode> ret;
         if (modification.getOperation() == LogicalOperation.DELETE) {
             if (modification.getChildren().isEmpty()) {
                 return delegate.apply(modification, storeMeta, version);
             }
             // Delete with children, implies it really is an empty write
-            ret = delegate.applyWrite(modification, emptyNode, storeMeta, version);
+            ret = Optional.of(delegate.applyWrite(modification, emptyNode, storeMeta, version));
         } else if (modification.getOperation() == LogicalOperation.TOUCH && !storeMeta.isPresent()) {
             ret = applyTouch(modification, storeMeta, version);
         } else {
             // No special handling required here, run normal apply operation
-            ret = delegate.apply(modification, storeMeta, version).get();
+            ret = delegate.apply(modification, storeMeta, version);
         }
 
-        return disappearResult(modification, ret, storeMeta);
+        return ret.isPresent() ? disappearResult(modification, ret.get(), storeMeta) : ret;
     }
 
     @Override
@@ -95,7 +95,7 @@ final class StructuralContainerModificationStrategy extends DelegatingModificati
         return Optional.of(TreeNodeFactory.createTreeNode(emptyNode, version));
     }
 
-    private TreeNode applyTouch(final ModifiedNode modification, final Optional<TreeNode> storeMeta,
+    private Optional<TreeNode> applyTouch(final ModifiedNode modification, final Optional<TreeNode> storeMeta,
             final Version version) {
         // Container is not present, let's take care of the 'magically appear' part of our job
         final Optional<TreeNode> ret = delegate.apply(modification, fakeMeta(version), version);
@@ -104,7 +104,7 @@ final class StructuralContainerModificationStrategy extends DelegatingModificati
         if (modification.getModificationType() == ModificationType.SUBTREE_MODIFIED) {
             modification.resolveModificationType(ModificationType.APPEARED);
         }
-        return ret.get();
+        return ret;
     }
 
     private static Optional<TreeNode> disappearResult(final ModifiedNode modification, final TreeNode result,