From: Robert Varga Date: Wed, 9 Apr 2014 03:48:36 +0000 (+0200) Subject: BUG-509: clean up comment X-Git-Tag: autorelease-tag-v20140601202136_82eb3f9~255 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=cf1bc562f10296aa8f16473bac6688b5e8727182 BUG-509: clean up comment This cleans up a comment why subtracting 1 from nesting is safe. It also adds a Preconditions.checkState() to explicitly guard on the expectation. Change-Id: Ia0b755d723d399b99fec98398afabba1222b97b3 Signed-off-by: Robert Varga --- diff --git a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/TreeNodeUtils.java b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/TreeNodeUtils.java index b2ec119ca9..339d9cb44e 100644 --- a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/TreeNodeUtils.java +++ b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/TreeNodeUtils.java @@ -80,11 +80,17 @@ public class TreeNodeUtils { final InstanceIdentifier currentPath = new InstanceIdentifier(path.getPath().subList(0, nesting)); return new SimpleEntry(currentPath,current.get()); } - // Nesting minus one is safe, since current is allways present when nesting = 0 - // so this prat of code is never triggered, in cases nesting == 0; + + /* + * Subtracting 1 from nesting level at this point is safe, because we + * cannot reach here with nesting == 0: that would mean the above check + * for current.isPresent() failed, which it cannot, as current is always + * present. At any rate we check state just to be on the safe side. + */ + Preconditions.checkState(nesting > 0); final InstanceIdentifier parentPath = new InstanceIdentifier(path.getPath().subList(0, nesting - 1)); - return new SimpleEntry(parentPath,parent.get()); + return new SimpleEntry(parentPath,parent.get()); } public static > Optional getChild(final Optional parent,final PathArgument child) {