Fix StatementMap$RegularAsCollection's size 53/79053/2
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 12 Sep 2018 09:29:40 +0000 (11:29 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 26 Dec 2018 02:32:41 +0000 (03:32 +0100)
We are not initializing the size field, hence the class does not
operate correctly. Fix that and correct isEmpty() method.

Change-Id: I1543e617f14f0a88c6b59afe93364cace151ee5c
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
(cherry picked from commit d94cd2529378a5544030c75bdb23b05d98092e05)

yang/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/StatementMap.java

index 6d3a5d746ee6217b188b9bd46741241a357dc643..3f33c988a6e1827f99a62973e55bb55a748a61b5 100644 (file)
@@ -10,7 +10,6 @@ package org.opendaylight.yangtools.yang.parser.stmt.reactor;
 import static com.google.common.base.Preconditions.checkArgument;
 import static java.util.Objects.requireNonNull;
 
-import com.google.common.base.Preconditions;
 import com.google.common.collect.AbstractIterator;
 import com.google.common.collect.ImmutableList;
 import java.util.AbstractCollection;
@@ -110,7 +109,7 @@ abstract class StatementMap {
 
         @Override
         Collection<StatementContextBase<?, ?, ?>> values() {
-            return new RegularAsCollection<>(elements);
+            return new RegularAsCollection<>(elements, size);
         }
 
         @Override
@@ -134,10 +133,11 @@ abstract class StatementMap {
 
     private static final class RegularAsCollection<T> extends AbstractCollection<T> {
         private final T[] elements;
-        private int size;
+        private final int size;
 
-        RegularAsCollection(final T[] elements) {
-            this.elements = Preconditions.checkNotNull(elements);
+        RegularAsCollection(final T[] elements, final int size) {
+            this.elements = requireNonNull(elements);
+            this.size = size;
         }
 
         @Override
@@ -149,11 +149,6 @@ abstract class StatementMap {
             }
         }
 
-        @Override
-        public boolean isEmpty() {
-            return size != 0;
-        }
-
         @Override
         public Iterator<T> iterator() {
             return new AbstractIterator<T>() {