X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;ds=sidebyside;f=opendaylight%2Fmd-sal%2Fsal-dom-broker%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fmd%2Fsal%2Fdom%2Fstore%2Fimpl%2Ftree%2FTreeNodeUtils.java;h=339d9cb44e2ed9515daa1eabbb8db2d913dab91a;hb=408eeef51f435abd2027f9d25ac5592066b202dd;hp=a2a706a9da3f84b197aaa80d57487b89ff2cb55b;hpb=335a9cfe42385a217ef002e4ab42f9cd958ad202;p=controller.git 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 a2a706a9da..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 @@ -43,7 +43,7 @@ public class TreeNodeUtils { public static > T findNodeChecked(final T tree, final InstanceIdentifier path) { T current = tree; - List nested = new ArrayList<>(path.getPath()); + List nested = new ArrayList<>(path.getPath().size()); for(PathArgument pathArg : path.getPath()) { Optional potential = current.getChild(pathArg); nested.add(pathArg); @@ -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) {