summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Pursehouse <david.pursehouse@sonymobile.com>2016-02-05 18:12:05 +0900
committerDavid Pursehouse <david.pursehouse@sonymobile.com>2016-02-05 18:12:05 +0900
commitb85e93046c51dccf0800bed2d33e61d3242da4f1 (patch)
tree2d9f197d732b2a88cf11f6ec3c9c605c8f01d9d9
parenta176c6055aed2baa818b46e836f13d24b203b358 (diff)
downloadjgit-b85e93046c51dccf0800bed2d33e61d3242da4f1.tar.gz
jgit-b85e93046c51dccf0800bed2d33e61d3242da4f1.zip
RepositoryTestCase: Open autocloseable types in try-with-resource
ObjectInserter.Formatter and Git are autocloseable and can be opened in try-with-resource to prevent a resource leak warning. Change-Id: I48c4001aaa7d9c1e36369e9799bfbb7c3bb46d8b Signed-off-by: David Pursehouse <david.pursehouse@sonymobile.com>
-rw-r--r--org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/RepositoryTestCase.java9
1 files changed, 5 insertions, 4 deletions
diff --git a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/RepositoryTestCase.java b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/RepositoryTestCase.java
index c649eb9086..0db71f7cbc 100644
--- a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/RepositoryTestCase.java
+++ b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/RepositoryTestCase.java
@@ -401,8 +401,7 @@ public abstract class RepositoryTestCase extends LocalDiskRepositoryTestCase {
* @return the created commit
*/
protected RevCommit commitFile(String filename, String contents, String branch) {
- try {
- Git git = new Git(db);
+ try (Git git = new Git(db)) {
Repository repo = git.getRepository();
String originalBranch = repo.getFullBranch();
boolean empty = repo.resolve(Constants.HEAD) == null;
@@ -443,8 +442,10 @@ public abstract class RepositoryTestCase extends LocalDiskRepositoryTestCase {
final int stage, final String content) {
final DirCacheEntry entry = new DirCacheEntry(path, stage);
entry.setFileMode(mode);
- entry.setObjectId(new ObjectInserter.Formatter().idFor(
- Constants.OBJ_BLOB, Constants.encode(content)));
+ try (ObjectInserter.Formatter formatter = new ObjectInserter.Formatter()) {
+ entry.setObjectId(formatter.idFor(
+ Constants.OBJ_BLOB, Constants.encode(content)));
+ }
return entry;
}