From 3212c8fa387995cecbb95de50508ba142f772203 Mon Sep 17 00:00:00 2001 From: Xing Huang Date: Tue, 21 Mar 2023 17:27:49 -0500 Subject: GC: Close File.lines stream 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 (cherry picked from commit 172a207945da376b6b4143305aef2af56f7c42e2) --- org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'org.eclipse.jgit') diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java index f25feee8f5..4fc9582d33 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java @@ -1683,8 +1683,9 @@ public class GC { private void gcAlreadyRunning() { close(); - try { - Optional s = Files.lines(pidFile).findFirst(); + Optional s; + try (Stream lines = Files.lines(pidFile)) { + s = lines.findFirst(); String machine = null; String pid = null; if (s.isPresent()) { -- cgit v1.2.3