From ca7d3e27342dfd98b041dc12a3094408f08b554d Mon Sep 17 00:00:00 2001 From: David Pursehouse Date: Mon, 26 Feb 2018 17:39:57 +0900 Subject: [PATCH] RecursiveMergerTest: Open FileOutputStream in try-with-resource Change-Id: I158333d6393fb807bc21fba23fec7ad474384471 Signed-off-by: David Pursehouse --- .../jgit/merge/RecursiveMergerTest.java | 61 +++++++++---------- 1 file changed, 28 insertions(+), 33 deletions(-) diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/RecursiveMergerTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/RecursiveMergerTest.java index 039a6e8cf..190224a85 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/RecursiveMergerTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/RecursiveMergerTest.java @@ -817,40 +817,35 @@ public class RecursiveMergerTest extends RepositoryTestCase { void modifyWorktree(WorktreeState worktreeState, String path, String other) throws Exception { - FileOutputStream fos = null; - ObjectId bloblId; - - try { - switch (worktreeState) { - case Missing: - new File(db.getWorkTree(), path).delete(); - break; - case DifferentFromHeadAndOther: - write(new File(db.getWorkTree(), path), - Integer.toString(counter++)); - break; - case SameAsHead: - bloblId = contentId(Constants.HEAD, path); - fos = new FileOutputStream(new File(db.getWorkTree(), path)); - db.newObjectReader().open(bloblId).copyTo(fos); - break; - case SameAsOther: - bloblId = contentId(other, path); - fos = new FileOutputStream(new File(db.getWorkTree(), path)); - db.newObjectReader().open(bloblId).copyTo(fos); - break; - case Bare: - if (db.isBare()) - return; - File workTreeFile = db.getWorkTree(); - db.getConfig().setBoolean("core", null, "bare", true); - db.getDirectory().renameTo(new File(workTreeFile, "test.git")); - db = new FileRepository(new File(workTreeFile, "test.git")); - db_t = new TestRepository<>(db); + switch (worktreeState) { + case Missing: + new File(db.getWorkTree(), path).delete(); + break; + case DifferentFromHeadAndOther: + write(new File(db.getWorkTree(), path), + Integer.toString(counter++)); + break; + case SameAsHead: + try (FileOutputStream fos = new FileOutputStream( + new File(db.getWorkTree(), path))) { + db.newObjectReader().open(contentId(Constants.HEAD, path)) + .copyTo(fos); } - } finally { - if (fos != null) - fos.close(); + break; + case SameAsOther: + try (FileOutputStream fos = new FileOutputStream( + new File(db.getWorkTree(), path))) { + db.newObjectReader().open(contentId(other, path)).copyTo(fos); + } + break; + case Bare: + if (db.isBare()) + return; + File workTreeFile = db.getWorkTree(); + db.getConfig().setBoolean("core", null, "bare", true); + db.getDirectory().renameTo(new File(workTreeFile, "test.git")); + db = new FileRepository(new File(workTreeFile, "test.git")); + db_t = new TestRepository<>(db); } }