From 4775a394c09be28860b50c3d29ac6c455b50260a Mon Sep 17 00:00:00 2001 From: David Pursehouse Date: Tue, 13 Mar 2018 20:24:45 +0900 Subject: [PATCH] SubmoduleWalk: Open Repository in try-with-resource Change-Id: Ib29aaf26b49aa94a5a7cc0b0264a0a93ecff0c16 Signed-off-by: David Pursehouse --- .../eclipse/jgit/submodule/SubmoduleWalk.java | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/submodule/SubmoduleWalk.java b/org.eclipse.jgit/src/org/eclipse/jgit/submodule/SubmoduleWalk.java index 2314cf10df..0fc11f697c 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/submodule/SubmoduleWalk.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/submodule/SubmoduleWalk.java @@ -754,13 +754,11 @@ public class SubmoduleWalk implements AutoCloseable { * @throws java.io.IOException */ public ObjectId getHead() throws IOException { - Repository subRepo = getRepository(); - if (subRepo == null) - return null; - try { + try (Repository subRepo = getRepository()) { + if (subRepo == null) { + return null; + } return subRepo.resolve(Constants.HEAD); - } finally { - subRepo.close(); } } @@ -771,14 +769,12 @@ public class SubmoduleWalk implements AutoCloseable { * @throws java.io.IOException */ public String getHeadRef() throws IOException { - Repository subRepo = getRepository(); - if (subRepo == null) - return null; - try { + try (Repository subRepo = getRepository()) { + if (subRepo == null) { + return null; + } Ref head = subRepo.exactRef(Constants.HEAD); return head != null ? head.getLeaf().getName() : null; - } finally { - subRepo.close(); } } -- 2.39.5