Browse Source

RecursiveMergerTest: Open TreeWalk and BufferedReader in try-with-resource

Change-Id: I381d535eb4ed7535ba8541c5320f81ce11d5b173
Signed-off-by: David Pursehouse <david.pursehouse@sonymobile.com>
stable-4.2
David Pursehouse 9 years ago
parent
commit
3adea9ac7f
  1. 29
      org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/RecursiveMergerTest.java

29
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();
}
}
}

Loading…
Cancel
Save