]> source.dussan.org Git - jgit.git/commitdiff
RefList: Support capacity <= 0 on new builders 67/100767/1
authorDave Borowitz <dborowitz@google.com>
Wed, 5 Jul 2017 17:32:35 +0000 (13:32 -0400)
committerDave Borowitz <dborowitz@google.com>
Wed, 5 Jul 2017 19:51:26 +0000 (15:51 -0400)
Callers may estimate the size, and their estimate may be zero. Silently
allow this, rather than throwing IndexOutOfBoundsException later during
add.

Change-Id: Ife236f9f4ce469c57b18e76cf4fad6feb52cb2b0

org.eclipse.jgit/src/org/eclipse/jgit/util/RefList.java

index 159781795ea09d52777fb81f57aabdf318c27fb4..ce4b7c75073799d38b63dfc296b14cfb8701b4b0 100644 (file)
@@ -338,10 +338,11 @@ public class RefList<T extends Ref> implements Iterable<Ref> {
                 * Create an empty list with at least the specified capacity.
                 *
                 * @param capacity
-                *            the new capacity.
+                *            the new capacity; if zero or negative, behavior is the same as
+                *            {@link #Builder()}.
                 */
                public Builder(int capacity) {
-                       list = new Ref[capacity];
+                       list = new Ref[Math.max(capacity, 16)];
                }
 
                /** @return number of items in this builder's internal collection. */