From 39b0b51b1253f569888db3578b01708a14360b69 Mon Sep 17 00:00:00 2001 From: Carsten Hammer Date: Thu, 11 Apr 2019 19:53:55 +0200 Subject: [PATCH] Use try-with-resources in SubmoduleWalk Convert try finally block to try-with-resources Change-Id: Ifd676a2aba3e926bd2f3b6b8fefd5f63564899ed Signed-off-by: Carsten Hammer Signed-off-by: Matthias Sohn --- .../eclipse/jgit/submodule/SubmoduleWalk.java | 26 +++++++++---------- 1 file changed, 12 insertions(+), 14 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 ce8995ad8..8f9fcc1bf 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/submodule/SubmoduleWalk.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/submodule/SubmoduleWalk.java @@ -149,21 +149,20 @@ public class SubmoduleWalk implements AutoCloseable { */ public static SubmoduleWalk forPath(Repository repository, AnyObjectId treeId, String path) throws IOException { - SubmoduleWalk generator = new SubmoduleWalk(repository); - try { + try (SubmoduleWalk generator = new SubmoduleWalk(repository)) { generator.setTree(treeId); PathFilter filter = PathFilter.create(path); generator.setFilter(filter); generator.setRootTree(treeId); - while (generator.next()) - if (filter.isDone(generator.walk)) + while (generator.next()) { + if (filter.isDone(generator.walk)) { return generator; + } + } + return null; } catch (IOException e) { - generator.close(); throw e; } - generator.close(); - return null; } /** @@ -182,21 +181,20 @@ public class SubmoduleWalk implements AutoCloseable { */ public static SubmoduleWalk forPath(Repository repository, AbstractTreeIterator iterator, String path) throws IOException { - SubmoduleWalk generator = new SubmoduleWalk(repository); - try { + try (SubmoduleWalk generator = new SubmoduleWalk(repository)) { generator.setTree(iterator); PathFilter filter = PathFilter.create(path); generator.setFilter(filter); generator.setRootTree(iterator); - while (generator.next()) - if (filter.isDone(generator.walk)) + while (generator.next()) { + if (filter.isDone(generator.walk)) { return generator; + } + } + return null; } catch (IOException e) { - generator.close(); throw e; } - generator.close(); - return null; } /**