Skip to content

Commit b1cdc12

Browse files
committed
[IO-811] Files.walk() direct and indirect callers fail to close the
returned Stream<Path> - Release resource in test
1 parent a44f413 commit b1cdc12

1 file changed

Lines changed: 13 additions & 8 deletions

File tree

src/test/java/org/apache/commons/io/function/IOBinaryOperatorStreamTest.java

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,19 @@ public void testMinBy() {
8888
public void testReduce() throws IOException {
8989
// A silly example to pass in a IOBinaryOperator.
9090
final Path current = PathUtils.current();
91-
final Path expected = Files.list(current).reduce((t, u) -> {
92-
try {
93-
return t.toRealPath();
94-
} catch (final IOException e) {
95-
return fail(e);
96-
}
97-
}).get();
98-
assertEquals(expected, Files.list(current).reduce(REAL_PATH_BO).get());
91+
final Path expected;
92+
try (Stream<Path> stream = Files.list(current)) {
93+
expected = stream.reduce((t, u) -> {
94+
try {
95+
return t.toRealPath();
96+
} catch (final IOException e) {
97+
return fail(e);
98+
}
99+
}).get();
100+
}
101+
try (Stream<Path> stream = Files.list(current)) {
102+
assertEquals(expected, stream.reduce(REAL_PATH_BO).get());
103+
}
99104
}
100105

101106
}

0 commit comments

Comments
 (0)