Skip to content

Commit 7f1cfe4

Browse files
committed
[IO-811] FileUtils.listFiles(File, String[], boolean) fails to close its
internal Stream Different version of solution from PR #489 by Adam Rauch
1 parent 6f4089e commit 7f1cfe4

2 files changed

Lines changed: 8 additions & 3 deletions

File tree

src/changes/changes.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,10 @@ The <action> type attribute can be add,update,fix,remove.
5555
Javadoc should mention closing Streams based on file resources.
5656
</action>
5757
<action dev="ggregory" type="fix" issue="IO-811" due-to="Adam Rauch, Gary Gregory">
58-
In tests, Files.walk() direct and indirect callers fail to close the returned Stream&lt;Path&gt;.
58+
In tests, Files.walk() direct and indirect callers fail to close the returned Stream.
59+
</action>
60+
<action dev="ggregory" type="fix" issue="IO-811" due-to="Adam Rauch, Gary Gregory">
61+
FileUtils.listFiles(File, String[], boolean) fails to close its internal Stream.
5962
</action>
6063
</release>
6164
<release version="2.14.0" date="2023-09-24" description="Java 8 is required.">

src/main/java/org/apache/commons/io/FileUtils.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2228,7 +2228,7 @@ public static Collection<File> listFiles(final File directory, final IOFileFilte
22282228
}
22292229

22302230
/**
2231-
* Finds files within a given directory (and optionally its subdirectories)
2231+
* Lists files within a given directory (and optionally its subdirectories)
22322232
* which match an array of extensions.
22332233
*
22342234
* @param directory the directory to search in
@@ -2238,7 +2238,9 @@ public static Collection<File> listFiles(final File directory, final IOFileFilte
22382238
* @return a collection of java.io.File with the matching files
22392239
*/
22402240
public static Collection<File> listFiles(final File directory, final String[] extensions, final boolean recursive) {
2241-
return Uncheck.apply(d -> toList(streamFiles(d, recursive, extensions)), directory);
2241+
try (Stream<File> fileStream = Uncheck.get(() -> streamFiles(directory, recursive, extensions))) {
2242+
return toList(fileStream);
2243+
}
22422244
}
22432245

22442246
/**

0 commit comments

Comments
 (0)