Browse Source

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
tags/v4.9.0.201710071750-r
Dave Borowitz 7 years ago
parent
commit
40748e8303
1 changed files with 3 additions and 2 deletions
  1. 3
    2
      org.eclipse.jgit/src/org/eclipse/jgit/util/RefList.java

+ 3
- 2
org.eclipse.jgit/src/org/eclipse/jgit/util/RefList.java View 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. */

Loading…
Cancel
Save