aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.pgm/src/org/eclipse
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.pgm/src/org/eclipse
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.pgm/src/org/eclipse')
-rw-r--r--org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Version.java11
-rw-r--r--org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/TextHashFunctions.java5
2 files changed, 4 insertions, 12 deletions
diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Version.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Version.java
index 5efc03b287..58acc5cafd 100644
--- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Version.java
+++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Version.java
@@ -96,14 +96,9 @@ class Version extends TextBuiltin {
}
private static String getBundleVersion(URL url) {
- try {
- InputStream is = url.openStream();
- try {
- Manifest manifest = new Manifest(is);
- return manifest.getMainAttributes().getValue("Bundle-Version"); //$NON-NLS-1$
- } finally {
- is.close();
- }
+ try (InputStream is = url.openStream()) {
+ Manifest manifest = new Manifest(is);
+ return manifest.getMainAttributes().getValue("Bundle-Version"); //$NON-NLS-1$
} catch (IOException e) {
// do nothing - will return null
}
diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/TextHashFunctions.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/TextHashFunctions.java
index 83b7bcea26..6378e8d220 100644
--- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/TextHashFunctions.java
+++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/TextHashFunctions.java
@@ -288,11 +288,8 @@ class TextHashFunctions extends TextBuiltin {
else
rb.findGitDir(dir);
- Repository repo = rb.build();
- try {
+ try (Repository repo = rb.build()) {
run(repo);
- } finally {
- repo.close();
}
}
}