This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-io.git
commit 7f1cfe4504a2e889d1ee1fa772a07182e2a2d8ad Author: Gary Gregory <garydgreg...@gmail.com> AuthorDate: Sun Oct 1 08:37:17 2023 -0400 [IO-811] FileUtils.listFiles(File, String[], boolean) fails to close its internal Stream Different version of solution from PR #489 by Adam Rauch --- src/changes/changes.xml | 5 ++++- src/main/java/org/apache/commons/io/FileUtils.java | 6 ++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 68558345..b1213828 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -55,7 +55,10 @@ The <action> type attribute can be add,update,fix,remove. Javadoc should mention closing Streams based on file resources. </action> <action dev="ggregory" type="fix" issue="IO-811" due-to="Adam Rauch, Gary Gregory"> - In tests, Files.walk() direct and indirect callers fail to close the returned Stream<Path>. + In tests, Files.walk() direct and indirect callers fail to close the returned Stream. + </action> + <action dev="ggregory" type="fix" issue="IO-811" due-to="Adam Rauch, Gary Gregory"> + FileUtils.listFiles(File, String[], boolean) fails to close its internal Stream. </action> </release> <release version="2.14.0" date="2023-09-24" description="Java 8 is required."> diff --git a/src/main/java/org/apache/commons/io/FileUtils.java b/src/main/java/org/apache/commons/io/FileUtils.java index 3cd8ce76..277ef3f0 100644 --- a/src/main/java/org/apache/commons/io/FileUtils.java +++ b/src/main/java/org/apache/commons/io/FileUtils.java @@ -2228,7 +2228,7 @@ public class FileUtils { } /** - * Finds files within a given directory (and optionally its subdirectories) + * Lists files within a given directory (and optionally its subdirectories) * which match an array of extensions. * * @param directory the directory to search in @@ -2238,7 +2238,9 @@ public class FileUtils { * @return a collection of java.io.File with the matching files */ public static Collection<File> listFiles(final File directory, final String[] extensions, final boolean recursive) { - return Uncheck.apply(d -> toList(streamFiles(d, recursive, extensions)), directory); + try (Stream<File> fileStream = Uncheck.get(() -> streamFiles(directory, recursive, extensions))) { + return toList(fileStream); + } } /**