aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.junit
diff options
context:
space:
mode:
authorDavid Pursehouse <david.pursehouse@gmail.com>2018-03-13 11:44:23 +0900
committerMatthias Sohn <matthias.sohn@sap.com>2018-03-13 22:16:06 +0100
commit5c70be00856d5375485e6f062b6e1e09a606601f (patch)
tree55726d1e2a1c52d75460a0a4336d487238037ba6 /org.eclipse.jgit.junit
parente23b09ad6efc35f6574cfefd4467ad20e5212ff2 (diff)
downloadjgit-5c70be00856d5375485e6f062b6e1e09a606601f.tar.gz
jgit-5c70be00856d5375485e6f062b6e1e09a606601f.zip
Open auto-closeable resources in try-with-resource
When an auto-closeable resources is not opened in try-with-resource, the warning "should be managed by try-with-resource" is emitted by Eclipse. Fix the ones that can be silenced simply by moving the declaration of the variable into a try-with-resource. In cases where we explicitly call the close() method, for example in tests where we are testing specific behavior caused by the close(), suppress the warning. Leave the ones that will require more significant refcactoring to fix. They can be done in separate commits that can be reviewed and tested in isolation. Change-Id: I9682cd20fb15167d3c7f9027cecdc82bc50b83c4 Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
Diffstat (limited to 'org.eclipse.jgit.junit')
-rw-r--r--org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/RepositoryTestCase.java33
1 files changed, 14 insertions, 19 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 5a83a1f492..93fc771cb3 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
@@ -94,20 +94,13 @@ public abstract class RepositoryTestCase extends LocalDiskRepositoryTestCase {
*/
protected static void copyFile(final File src, final File dst)
throws IOException {
- final FileInputStream fis = new FileInputStream(src);
- try {
- final FileOutputStream fos = new FileOutputStream(dst);
- try {
- final byte[] buf = new byte[4096];
- int r;
- while ((r = fis.read(buf)) > 0) {
- fos.write(buf, 0, r);
- }
- } finally {
- fos.close();
+ try (FileInputStream fis = new FileInputStream(src);
+ FileOutputStream fos = new FileOutputStream(dst)) {
+ final byte[] buf = new byte[4096];
+ int r;
+ while ((r = fis.read(buf)) > 0) {
+ fos.write(buf, 0, r);
}
- } finally {
- fis.close();
}
}
@@ -293,10 +286,11 @@ public abstract class RepositoryTestCase extends LocalDiskRepositoryTestCase {
dce.setFileMode(treeItr.getEntryFileMode());
dce.setLastModified(treeItr.getEntryLastModified());
dce.setLength((int) len);
- FileInputStream in = new FileInputStream(
- treeItr.getEntryFile());
- dce.setObjectId(inserter.insert(Constants.OBJ_BLOB, len, in));
- in.close();
+ try (FileInputStream in = new FileInputStream(
+ treeItr.getEntryFile())) {
+ dce.setObjectId(
+ inserter.insert(Constants.OBJ_BLOB, len, in));
+ }
builder.add(dce);
treeItr.next(1);
}
@@ -380,8 +374,9 @@ public abstract class RepositoryTestCase extends LocalDiskRepositoryTestCase {
while (actTime <= startTime) {
Thread.sleep(sleepTime);
sleepTime *= 2;
- FileOutputStream fos = new FileOutputStream(tmp);
- fos.close();
+ try (FileOutputStream fos = new FileOutputStream(tmp)) {
+ // Do nothing
+ }
actTime = fs.lastModified(tmp);
}
return actTime;