Skip to content

Commit 264caa9

Browse files
artembilangaryrussell
authored andcommitted
GH-2478: RecursiveDScanner: Files.walk().close()
Fixes #2478 The `Files.walk()` stream must be closed in the end after usage * Wrap `Files.walk()` to the `try-with-resources` **Cherry-pick to 5.0.x**
1 parent 058ae6f commit 264caa9

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

spring-integration-file/src/main/java/org/springframework/integration/file/RecursiveDirectoryScanner.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017 the original author or authors.
2+
* Copyright 2017-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -70,12 +70,13 @@ public void setFileVisitOptions(FileVisitOption... fileVisitOptions) {
7070
public List<File> listFiles(File directory) throws IllegalArgumentException {
7171
FileListFilter<File> filter = getFilter();
7272
boolean supportAcceptFilter = filter instanceof AbstractFileListFilter;
73-
try {
74-
Stream<File> fileStream = Files.walk(directory.toPath(), this.maxDepth, this.fileVisitOptions)
75-
.skip(1)
76-
.map(Path::toFile)
77-
.filter(file -> !supportAcceptFilter
78-
|| ((AbstractFileListFilter<File>) filter).accept(file));
73+
try (Stream<Path> pathStream = Files.walk(directory.toPath(), this.maxDepth, this.fileVisitOptions);) {
74+
Stream<File> fileStream =
75+
pathStream
76+
.skip(1)
77+
.map(Path::toFile)
78+
.filter(file -> !supportAcceptFilter
79+
|| ((AbstractFileListFilter<File>) filter).accept(file));
7980

8081
if (supportAcceptFilter) {
8182
return fileStream.collect(Collectors.toList());

0 commit comments

Comments
 (0)