Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Pursehouse2016-02-11 23:48:54 -0500
committerDavid Pursehouse2016-02-11 23:48:54 -0500
commit3adea9ac7fb916f1cd3aebea5dacac92da749da6 (patch)
tree5e157a13333c8cbcdc3b6043687dff7b94255cd2
parent964da41d52258e88d4f79b0d483a7ee5505c7f0e (diff)
downloadjgit-3adea9ac7fb916f1cd3aebea5dacac92da749da6.tar.gz
jgit-3adea9ac7fb916f1cd3aebea5dacac92da749da6.tar.xz
jgit-3adea9ac7fb916f1cd3aebea5dacac92da749da6.zip
RecursiveMergerTest: Open TreeWalk and BufferedReader in try-with-resource
Change-Id: I381d535eb4ed7535ba8541c5320f81ce11d5b173 Signed-off-by: David Pursehouse <david.pursehouse@sonymobile.com>
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/RecursiveMergerTest.java29
1 files changed, 14 insertions, 15 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 7ef6448e57..0e7109c58a 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
@@ -872,32 +872,31 @@ public class RecursiveMergerTest extends RepositoryTestCase {
private String contentAsString(Repository r, ObjectId treeId, String path)
throws MissingObjectException, IOException {
- TreeWalk tw = new TreeWalk(r);
- tw.addTree(treeId);
- tw.setFilter(PathFilter.create(path));
- tw.setRecursive(true);
- if (!tw.next())
- return null;
- AnyObjectId blobId = tw.getObjectId(0);
+ AnyObjectId blobId;
+ try (TreeWalk tw = new TreeWalk(r)) {
+ tw.addTree(treeId);
+ tw.setFilter(PathFilter.create(path));
+ tw.setRecursive(true);
+ if (!tw.next()) {
+ return null;
+ }
+ blobId = tw.getObjectId(0);
+ }
StringBuilder result = new StringBuilder();
- BufferedReader br = null;
ObjectReader or = r.newObjectReader();
- try {
- br = new BufferedReader(new InputStreamReader(or.open(blobId)
- .openStream()));
+ try (BufferedReader br = new BufferedReader(
+ new InputStreamReader(or.open(blobId).openStream()))) {
String line;
boolean first = true;
while ((line = br.readLine()) != null) {
- if (!first)
+ if (!first) {
result.append('\n');
+ }
result.append(line);
first = false;
}
return result.toString();
- } finally {
- if (br != null)
- br.close();
}
}
}

Back to the top