]> source.dussan.org Git - jgit.git/commitdiff
GC: Close File.lines stream 89/200789/2
authorXing Huang <xingkhuang@google.com>
Tue, 21 Mar 2023 22:27:49 +0000 (17:27 -0500)
committerMatthias Sohn <matthias.sohn@sap.com>
Thu, 23 Mar 2023 07:19:26 +0000 (08:19 +0100)
From File#lines javadoc: The returned stream from File Lines
encapsulates a Reader. If timely disposal of file system resources is
required, the try-with-resources construct should be used to ensure
that the stream's close method is
invoked after the stream operations are completed.

Wrap File.lines with try-with-resources.

Change-Id: I82c6faa3ef1083f6c7e964f96e9540b4db18eee8
Signed-off-by: Xing Huang <xingkhuang@google.com>
(cherry picked from commit 172a207945da376b6b4143305aef2af56f7c42e2)

org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java

index f25feee8f5cdfddf53608f6a2c5a2e32d673a43b..4fc9582d333f45f179dd9333b4908b77e2a3b9c2 100644 (file)
@@ -1683,8 +1683,9 @@ public class GC {
 
                private void gcAlreadyRunning() {
                        close();
-                       try {
-                               Optional<String> s = Files.lines(pidFile).findFirst();
+                       Optional<String> s;
+                       try (Stream<String> lines = Files.lines(pidFile)) {
+                               s = lines.findFirst();
                                String machine = null;
                                String pid = null;
                                if (s.isPresent()) {