diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/ArchiveCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/ArchiveCommand.java index 713866dc5..5f31be69f 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/ArchiveCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/ArchiveCommand.java @@ -364,10 +364,11 @@ public class ArchiveCommand extends GitCommand { } private OutputStream writeArchive(Format fmt) { - final String pfx = prefix == null ? "" : prefix; //$NON-NLS-1$ - try (final TreeWalk walk = new TreeWalk(repo)) { - final T outa = fmt.createArchiveOutputStream(out, formatOptions); - try (final RevWalk rw = new RevWalk(walk.getObjectReader())) { + try { + try (TreeWalk walk = new TreeWalk(repo); + RevWalk rw = new RevWalk(walk.getObjectReader())) { + final String pfx = prefix == null ? "" : prefix; //$NON-NLS-1$ + final T outa = fmt.createArchiveOutputStream(out, formatOptions); final MutableObjectId idBuf = new MutableObjectId(); final ObjectReader reader = walk.getObjectReader(); @@ -376,7 +377,7 @@ public class ArchiveCommand extends GitCommand { walk.setFilter(PathFilterGroup.createFromStrings(paths)); while (walk.next()) { - final String name = pfx + walk.getPathString(); + String name = pfx + walk.getPathString(); FileMode mode = walk.getFileMode(0); if (walk.isSubtree()) @@ -395,10 +396,10 @@ public class ArchiveCommand extends GitCommand { fmt.putEntry(outa, name, mode, reader.open(idBuf)); } outa.close(); + return out; } finally { out.close(); } - return out; } catch (IOException e) { // TODO(jrn): Throw finer-grained errors. throw new JGitInternalException(