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>
This commit is contained in:
parent
a176c6055a
commit
b85e93046c
|
@ -401,8 +401,7 @@ protected File writeTrashFiles(boolean ensureDistinctTimestamps,
|
||||||
* @return the created commit
|
* @return the created commit
|
||||||
*/
|
*/
|
||||||
protected RevCommit commitFile(String filename, String contents, String branch) {
|
protected RevCommit commitFile(String filename, String contents, String branch) {
|
||||||
try {
|
try (Git git = new Git(db)) {
|
||||||
Git git = new Git(db);
|
|
||||||
Repository repo = git.getRepository();
|
Repository repo = git.getRepository();
|
||||||
String originalBranch = repo.getFullBranch();
|
String originalBranch = repo.getFullBranch();
|
||||||
boolean empty = repo.resolve(Constants.HEAD) == null;
|
boolean empty = repo.resolve(Constants.HEAD) == null;
|
||||||
|
@ -443,8 +442,10 @@ protected DirCacheEntry createEntry(final String path, final FileMode mode,
|
||||||
final int stage, final String content) {
|
final int stage, final String content) {
|
||||||
final DirCacheEntry entry = new DirCacheEntry(path, stage);
|
final DirCacheEntry entry = new DirCacheEntry(path, stage);
|
||||||
entry.setFileMode(mode);
|
entry.setFileMode(mode);
|
||||||
entry.setObjectId(new ObjectInserter.Formatter().idFor(
|
try (ObjectInserter.Formatter formatter = new ObjectInserter.Formatter()) {
|
||||||
Constants.OBJ_BLOB, Constants.encode(content)));
|
entry.setObjectId(formatter.idFor(
|
||||||
|
Constants.OBJ_BLOB, Constants.encode(content)));
|
||||||
|
}
|
||||||
return entry;
|
return entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue