aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Pursehouse <david.pursehouse@gmail.com>2018-01-10 16:30:28 +0900
committerDavid Pursehouse <david.pursehouse@gmail.com>2018-01-10 16:39:20 +0900
commit338d0a81bb29ffedaef83024db1b1f8026841af5 (patch)
tree7f3279d4ceb54342586899937a4239f6873bb712
parentd20363b114d11e183a4c9464ab0dc24061223f2e (diff)
downloadjgit-338d0a81bb29ffedaef83024db1b1f8026841af5.tar.gz
jgit-338d0a81bb29ffedaef83024db1b1f8026841af5.zip
RefDirectory#hasLooseRef: Fix stream resource leak reported by error-prone
Error-prone reports: [StreamResourceLeak] Streams that encapsulate a closeable resource should be closed using try-with-resources Change-Id: I86154fba2b896723feaecf8991ed3c8e96ea2499 Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java6
1 files changed, 5 insertions, 1 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java
index 20302d124b..4495e09517 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java
@@ -66,6 +66,7 @@ import java.io.IOException;
import java.io.InputStreamReader;
import java.io.InterruptedIOException;
import java.nio.file.Files;
+import java.nio.file.Path;
import java.security.DigestInputStream;
import java.security.MessageDigest;
import java.text.MessageFormat;
@@ -78,6 +79,7 @@ import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import java.util.concurrent.locks.ReentrantLock;
+import java.util.stream.Stream;
import org.eclipse.jgit.annotations.NonNull;
import org.eclipse.jgit.annotations.Nullable;
@@ -1220,7 +1222,9 @@ public class RefDirectory extends RefDatabase {
}
private boolean hasLooseRef() throws IOException {
- return Files.walk(refsDir.toPath()).anyMatch(Files::isRegularFile);
+ try (Stream<Path> stream = Files.walk(refsDir.toPath())) {
+ return stream.anyMatch(Files::isRegularFile);
+ }
}
/** If the parent should fire listeners, fires them. */