From acc94c475a4d2635584798d43a3e47a81b2b2751 Mon Sep 17 00:00:00 2001 From: David Pursehouse Date: Fri, 27 Jan 2017 14:44:14 +0900 Subject: [PATCH] RepoCommand#readFile: Don't call Git#getRepository() in try-with-resource Using try-with-resource means that close() will automatically be called on the Repository object. However, according to the javadoc of Git#close(): If the repository was opened by a static factory method in this class, then this method calls Repository#close() on the underlying repository instance. This means that Repository#close() is called twice, by Git.close() and in the outer try-with-resource, leading to a corrupt use count. Change-Id: I37ba517eb2cc67d1cd36813598772c70208d0bc9 Signed-off-by: David Pursehouse --- .../src/org/eclipse/jgit/gitrepo/RepoCommand.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoCommand.java index 86dbabca0b..d18cd97489 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoCommand.java @@ -181,9 +181,8 @@ public class RepoCommand extends GitCommand { throws GitAPIException, IOException { File dir = FileUtils.createTempDir("jgit_", ".git", null); //$NON-NLS-1$ //$NON-NLS-2$ try (Git git = Git.cloneRepository().setBare(true).setDirectory(dir) - .setURI(uri).call(); - Repository repo = git.getRepository()) { - return readFileFromRepo(repo, ref, path); + .setURI(uri).call()) { + return readFileFromRepo(git.getRepository(), ref, path); } finally { FileUtils.delete(dir, FileUtils.RECURSIVE); } -- 2.39.5