LfsProjectLocks: Open Files.list stream in try-with-resource
When building with Bazel 0.10.rc8, ErrorProne reports an error:
[StreamResourceLeak] Streams that encapsulate a closeable resource
should be closed using try-with-resources
Change-Id: I4685d5c72a39411ef5605fe873a5a62fd4e8eaa9
Reported-by: David Ostrovsky <david@ostrovsky.org>
diff --git a/src/main/java/com/googlesource/gerrit/plugins/lfs/locks/LfsProjectLocks.java b/src/main/java/com/googlesource/gerrit/plugins/lfs/locks/LfsProjectLocks.java
index 346bdad..c9e0d28 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/lfs/locks/LfsProjectLocks.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/lfs/locks/LfsProjectLocks.java
@@ -32,6 +32,7 @@
import java.nio.file.Paths;
import java.util.Collection;
import java.util.Optional;
+import java.util.stream.Stream;
import org.eclipse.jgit.internal.storage.file.LockFile;
import org.eclipse.jgit.lfs.errors.LfsException;
import org.joda.time.DateTime;
@@ -72,8 +73,8 @@
if (!Files.exists(locksPath)) {
return;
}
- try {
- Files.list(locksPath)
+ try (Stream<Path> stream = Files.list(locksPath)) {
+ stream
.filter(Files::isRegularFile)
.forEach(
path -> {