Fix NONE operation node with automatic lifecycle 25/81425/2
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 8 Apr 2019 01:10:04 +0000 (03:10 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 8 Apr 2019 01:10:04 +0000 (03:10 +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>
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/AutomaticLifecycleMixin.java

index 006bdd61421329b0cf35fc5a09c16134a7875fba..c2705ec5678d1d73e49f12c4a32370423c6d85d8 100644 (file)
@@ -49,24 +49,24 @@ final class AutomaticLifecycleMixin {
         // 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 = writeDelegate.applyWrite(modification, emptyNode, storeMeta, version);
+            ret = Optional.of(writeDelegate.applyWrite(modification, emptyNode, storeMeta, version));
         } else if (modification.getOperation() == LogicalOperation.TOUCH && !storeMeta.isPresent()) {
             ret = applyTouch(delegate, emptyNode, 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;
     }
 
-    private static TreeNode applyTouch(final Apply delegate, final NormalizedNode<?, ?> emptyNode,
+    private static Optional<TreeNode> applyTouch(final Apply delegate, final NormalizedNode<?, ?> emptyNode,
             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(emptyNode, version), version);
@@ -75,7 +75,7 @@ final class AutomaticLifecycleMixin {
         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,