Bug 3344: Make sure StackedPathArgument stack is non empty. 95/21795/3
authorTony Tkacik <ttkacik@cisco.com>
Wed, 3 Jun 2015 15:26:32 +0000 (17:26 +0200)
committerRobert Varga <nite@hq.sk>
Wed, 3 Jun 2015 16:03:16 +0000 (16:03 +0000)
The while cycle in StackedYangInstanceIdentifier did double
check of tryPathArguments for same instance identifier,
which led to shared state during creation. This may have
resulted in StackedPathArgumements with empty stack.

Changing it into do-while cycle makes sure stack is non empty
and also state during construction is not shared between
multiple invokers.

Change-Id: I834c1f22c477bb03a6bae9c4a366308a0988ce4e
Signed-off-by: Tony Tkacik <ttkacik@cisco.com>
yang/yang-data-api/src/main/java/org/opendaylight/yangtools/yang/data/api/StackedPathArguments.java
yang/yang-data-api/src/main/java/org/opendaylight/yangtools/yang/data/api/StackedYangInstanceIdentifier.java

index 93dde99d1ed97999de70feb6cb332677cb54cfd7..ffe52c02c1cdbab0093b66fcc7a09d60870d0f49 100644 (file)
@@ -7,18 +7,21 @@
 package org.opendaylight.yangtools.yang.data.api;
 
 import com.google.common.base.Preconditions;
+import com.google.common.base.Verify;
 import com.google.common.collect.UnmodifiableIterator;
 import java.util.Iterator;
 import java.util.List;
+import javax.annotation.Nonnull;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
 
 final class StackedPathArguments extends PathArgumentList {
     private final List<PathArgument> base;
     private final List<PathArgument> stack;
 
-    public StackedPathArguments(final YangInstanceIdentifier base, final List<PathArgument> stack) {
+    public StackedPathArguments(@Nonnull final YangInstanceIdentifier base, @Nonnull final List<PathArgument> stack) {
+        Verify.verify(!stack.isEmpty());
         this.base = base.getPathArguments();
-        this.stack = Preconditions.checkNotNull(stack);
+        this.stack = stack;
     }
 
     @Override
index ac1d8606ac7be91f23ebaca5225638398164b88d..816a082a3dab9385e15e749e1873a3dc1a5a9cc1 100644 (file)
@@ -59,15 +59,14 @@ final class StackedYangInstanceIdentifier extends YangInstanceIdentifier {
     public List<PathArgument> getPathArguments() {
         StackedPathArguments ret = tryPathArguments();
         if (ret == null) {
-            List<PathArgument> stack = new ArrayList<>();
+            final List<PathArgument> stack = new ArrayList<>();
             YangInstanceIdentifier current = this;
-            while (current.tryPathArguments() == null) {
+            do {
                 Verify.verify(current instanceof StackedYangInstanceIdentifier);
-
                 final StackedYangInstanceIdentifier stacked = (StackedYangInstanceIdentifier) current;
                 stack.add(stacked.getLastPathArgument());
                 current = stacked.getParent();
-            }
+            } while (current.tryPathArguments() == null);
 
             ret = new StackedPathArguments(current, Lists.reverse(stack));
             pathArguments = ret;