Convert to new AutoCloseable instances coming in JGit 4.0

Repository, RevWalk, and friends have been converted to AutoCloseable.
Use them in try-with-resources blocks in order to avoid warnings about
unclosed resources or calls to deprecated release() methods. Where a
larger rewrite might have been possible to reduce try/finally blocks,
err on the side of keeping the same behavior.

The proximate goal of this change was to eliminate all Eclipse
warnings about deprecated method calls (namely release()) and leaked
resources. Some of these warnings were in fact potential leaks;
Eclipse finding such cases is a side benefit of having these classes
implement AutoCloseable. However, this change certainly does not cover
all cases where try-with-resources could have been used, where it was
not causing a leak.

Fixes all such warnings in plugin submodules as well.

Change-Id: I5d151996ae012d0e8fdfa27cce8cf5e2bfc856a2
This commit is contained in:
Dave Borowitz
2015-03-10 16:10:59 -07:00
parent 81061fc2bc
commit 16f552165a
55 changed files with 1107 additions and 1446 deletions

View File

@@ -73,11 +73,10 @@ public class PRED_commit_edits_2 extends Predicate.P2 {
PatchList pl = StoredValues.PATCH_LIST.get(engine);
Repository repo = StoredValues.REPOSITORY.get(engine);
final ObjectReader reader = repo.newObjectReader();
final RevTree aTree;
final RevTree bTree;
try {
final RevWalk rw = new RevWalk(reader);
try (ObjectReader reader = repo.newObjectReader();
RevWalk rw = new RevWalk(reader)) {
final RevTree aTree;
final RevTree bTree;
final RevCommit bCommit = rw.parseCommit(pl.getNewId());
if (pl.getOldId() != null) {
@@ -129,8 +128,6 @@ public class PRED_commit_edits_2 extends Predicate.P2 {
}
} catch (IOException err) {
throw new JavaException(this, 1, err);
} finally {
reader.release();
}
return engine.fail();
@@ -161,4 +158,4 @@ public class PRED_commit_edits_2 extends Predicate.P2 {
}
return new Text(reader.open(tw.getObjectId(0), Constants.OBJ_BLOB));
}
}
}