From 40748e83039f2a8ac77a17fd09ea109ae6382e51 Mon Sep 17 00:00:00 2001 From: Dave Borowitz Date: Wed, 5 Jul 2017 13:32:35 -0400 Subject: [PATCH] RefList: Support capacity <= 0 on new builders 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 | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/RefList.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/RefList.java index 159781795..ce4b7c750 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/RefList.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/RefList.java @@ -338,10 +338,11 @@ public class RefList implements Iterable { * 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. */