From f0ef5e1ef09d346432fead17bc82d78b7cfbd621 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Wed, 14 May 2008 21:16:07 -0400 Subject: [PATCH] Always initialize TreeWalk with a single empty tree By loading a single empty tree iterator into the tree walk's initial list of trees we can avoid array index out of bound exceptions if the application tries to call next() prior to actually giving us a tree to iterate. This can simplify a few application cases where we may need to advance an open tree walk, or load a new tree into one if we are already at the end and have no more entries. Signed-off-by: Shawn O. Pearce --- org.spearce.jgit/src/org/spearce/jgit/treewalk/TreeWalk.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/org.spearce.jgit/src/org/spearce/jgit/treewalk/TreeWalk.java b/org.spearce.jgit/src/org/spearce/jgit/treewalk/TreeWalk.java index 49fafc5e..d7927c77 100644 --- a/org.spearce.jgit/src/org/spearce/jgit/treewalk/TreeWalk.java +++ b/org.spearce.jgit/src/org/spearce/jgit/treewalk/TreeWalk.java @@ -122,7 +122,7 @@ public class TreeWalk { private TreeFilter filter; - private AbstractTreeIterator[] trees = {}; + private AbstractTreeIterator[] trees; private boolean recursive; @@ -141,6 +141,7 @@ public class TreeWalk { public TreeWalk(final Repository repo) { db = repo; filter = TreeFilter.ALL; + trees = new AbstractTreeIterator[] { new EmptyTreeIterator() }; } /** -- 2.11.4.GIT