Add an explicit guard for root presence 93/19693/3
authorRobert Varga <rovarga@cisco.com>
Wed, 6 May 2015 09:57:35 +0000 (11:57 +0200)
committerRobert Varga <nite@hq.sk>
Wed, 13 May 2015 09:47:03 +0000 (09:47 +0000)
A modification could potentially remove the root node, which would
trigger a failure in Optional.get(). Add an explicit check to provide
better diagnostic in that case.

Change-Id: I0e27910497169a080aa8185c66f65c9639ccf2e7
Signed-off-by: Robert Varga <rovarga@cisco.com>
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/InMemoryDataTreeModification.java

index 2dda1b3f654fc38527d6849b674e6315f6540bad..817110a8f126fc8f7dc69ff2465e7a71e9fa2082 100644 (file)
@@ -195,6 +195,7 @@ final class InMemoryDataTreeModification implements DataTreeModification {
          */
         TreeNode originalSnapshotRoot = snapshot.getRootNode();
         Optional<TreeNode> tempRoot = strategyTree.apply(rootNode, Optional.of(originalSnapshotRoot), version);
+        Preconditions.checkState(tempRoot.isPresent(), "Data tree root is not present, possibly removed by previous modification");
 
         InMemoryDataTreeSnapshot tempTree = new InMemoryDataTreeSnapshot(snapshot.getSchemaContext(), tempRoot.get(), strategyTree);
         return tempTree.newModification();