summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Sohn <matthias.sohn@sap.com>2015-04-02 01:21:55 +0200
committerMatthias Sohn <matthias.sohn@sap.com>2015-04-02 01:21:55 +0200
commitd6692d54a96fe58699213e881c39227666729b5a (patch)
treeca98e2fd01090d29768071a83cd2bc5e4d8200e3
parentd94ce9c754b740defbd75230663d323f64cc9648 (diff)
downloadjgit-d6692d54a96fe58699213e881c39227666729b5a.tar.gz
jgit-d6692d54a96fe58699213e881c39227666729b5a.zip
Use try-with-resource to close resources in BlobBasedConfig
Change-Id: Idb890788a88049d07326cd48e7c5534148f18e32 Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/lib/BlobBasedConfig.java14
1 files changed, 5 insertions, 9 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/BlobBasedConfig.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/BlobBasedConfig.java
index a0197d022a..cbb2f5b856 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/BlobBasedConfig.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/BlobBasedConfig.java
@@ -104,11 +104,8 @@ public class BlobBasedConfig extends Config {
private static byte[] read(Repository db, AnyObjectId blobId)
throws MissingObjectException, IncorrectObjectTypeException,
IOException {
- ObjectReader or = db.newObjectReader();
- try {
+ try (ObjectReader or = db.newObjectReader()) {
return read(or, blobId);
- } finally {
- or.release();
}
}
@@ -146,15 +143,12 @@ public class BlobBasedConfig extends Config {
private static byte[] read(Repository db, AnyObjectId treeish, String path)
throws MissingObjectException, IncorrectObjectTypeException,
IOException {
- ObjectReader or = db.newObjectReader();
- try {
+ try (ObjectReader or = db.newObjectReader()) {
TreeWalk tree = TreeWalk.forPath(or, path, asTree(or, treeish));
if (tree == null)
throw new FileNotFoundException(MessageFormat.format(JGitText
.get().entryNotFoundByPath, path));
return read(or, tree.getObjectId(0));
- } finally {
- or.release();
}
}
@@ -168,6 +162,8 @@ public class BlobBasedConfig extends Config {
&& ((RevCommit) treeish).getTree() != null)
return ((RevCommit) treeish).getTree();
- return new RevWalk(or).parseTree(treeish).getId();
+ try (RevWalk rw = new RevWalk(or)) {
+ return rw.parseTree(treeish).getId();
+ }
}
}