Merge "Fix checkstyle if-statements must use braces in yang-parser-impl"
[yangtools.git] / yang / yang-data-impl / src / main / java / org / opendaylight / yangtools / yang / data / impl / schema / tree / ModifiedNode.java
index c4933d08b3aeb22c46d76f778cb8a358ece0ecfc..90e83ca401c213e269f8b61c0ba309c67b5775b8 100644 (file)
@@ -169,10 +169,35 @@ final class ModifiedNode implements StoreTreeNode<ModifiedNode>, Identifiable<Pa
      *
      */
     public void delete() {
+        final ModificationType newType;
+
+        switch (modificationType) {
+        case DELETE:
+        case UNMODIFIED:
+            // We need to record this delete.
+            newType = ModificationType.DELETE;
+            break;
+        case MERGE:
+        case SUBTREE_MODIFIED:
+        case WRITE:
+            /*
+             * We are canceling a previous modification. This is a bit tricky,
+             * as the original write may have just introduced the data, or it
+             * may have modified it.
+             *
+             * As documented in BUG-2470, a delete of data introduced in this
+             * transaction needs to be turned into a no-op.
+             */
+            newType = original.isPresent() ? ModificationType.DELETE : ModificationType.UNMODIFIED;
+            break;
+        default:
+            throw new IllegalStateException("Unhandled deletion of node with " + modificationType);
+        }
+
         clearSnapshot();
-        updateModificationType(ModificationType.DELETE);
         children.clear();
         this.value = null;
+        updateModificationType(newType);
     }
 
     /**