Move lookup check 61/46361/1
authorRobert Varga <rovarga@cisco.com>
Tue, 20 Sep 2016 14:00:03 +0000 (16:00 +0200)
committerRobert Varga <rovarga@cisco.com>
Mon, 3 Oct 2016 11:36:21 +0000 (13:36 +0200)
We can use a precondition to make the code flow
more obvious.

Change-Id: Iaddfcfd4d49a91b6875a6f4803fed744ada63a85
Signed-off-by: Robert Varga <rovarga@cisco.com>
(cherry picked from commit bf69b6948754f6b1a7de124cc54bbe88b3532772)

dom/mdsal-dom-broker/src/main/java/org/opendaylight/mdsal/dom/broker/ShardedDOMDataTreeWriteTransaction.java

index 272d806e884719b6be79b0d52731508614a03143..bbe26b0549c016d7c49c3557ccf1231b0c35d268 100644 (file)
@@ -83,8 +83,7 @@ final class ShardedDOMDataTreeWriteTransaction implements DOMDataTreeCursorAware
             }
         }
 
-        throw new IllegalArgumentException(String.format("Path %s is not accessible from transaction %s",
-                prefix, this));
+        return null;
     }
 
     @Override
@@ -115,7 +114,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;
     }