Move lookup check 94/45894/4
authorRobert Varga <rovarga@cisco.com>
Tue, 20 Sep 2016 14:00:03 +0000 (16:00 +0200)
committerRobert Varga <rovarga@cisco.com>
Wed, 21 Sep 2016 11:50:41 +0000 (13:50 +0200)
We can use a precondition to make the code flow
more obvious.

Change-Id: Iaddfcfd4d49a91b6875a6f4803fed744ada63a85
Signed-off-by: Robert Varga <rovarga@cisco.com>
dom/mdsal-dom-broker/src/main/java/org/opendaylight/mdsal/dom/broker/ShardedDOMDataTreeWriteTransaction.java

index 08f359d2161e9dcb64f2c9042b45a6f62ab93710..ab41a4bc5e8e35979fcbc6d0b13c2d32fe36c920 100644 (file)
@@ -76,8 +76,7 @@ final class ShardedDOMDataTreeWriteTransaction implements DOMDataTreeCursorAware
             }
         }
 
-        throw new IllegalArgumentException(String.format("Path %s is not accessible from transaction %s",
-                prefix, this));
+        return null;
     }
 
     @Override
@@ -108,7 +107,10 @@ final class ShardedDOMDataTreeWriteTransaction implements DOMDataTreeCursorAware
     public synchronized DOMDataTreeWriteCursor createCursor(final DOMDataTreeIdentifier prefix) {
         Preconditions.checkState(!closed, "Transaction is closed already");
         Preconditions.checkState(openCursor == null, "There is still a cursor open");
+
         final DOMDataTreeShardWriteTransaction lookup = lookup(prefix);
+        Preconditions.checkArgument(lookup != null, "Path %s is not accessible from transaction %s", prefix, this);
+
         openCursor = new DelegatingCursor(lookup.createCursor(prefix), prefix);
         return openCursor;
     }