From 264caa992fdd1f9a110129b53a99a961589f0866 Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Wed, 13 Jun 2018 11:59:33 -0400 Subject: [PATCH] GH-2478: RecursiveDScanner: Files.walk().close() Fixes https://github.com/spring-projects/spring-integration/issues/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** --- .../file/RecursiveDirectoryScanner.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/spring-integration-file/src/main/java/org/springframework/integration/file/RecursiveDirectoryScanner.java b/spring-integration-file/src/main/java/org/springframework/integration/file/RecursiveDirectoryScanner.java index 8657ff8ade..dc32bb0d3d 100644 --- a/spring-integration-file/src/main/java/org/springframework/integration/file/RecursiveDirectoryScanner.java +++ b/spring-integration-file/src/main/java/org/springframework/integration/file/RecursiveDirectoryScanner.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 the original author or authors. + * Copyright 2017-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -70,12 +70,13 @@ public class RecursiveDirectoryScanner extends DefaultDirectoryScanner { public List listFiles(File directory) throws IllegalArgumentException { FileListFilter filter = getFilter(); boolean supportAcceptFilter = filter instanceof AbstractFileListFilter; - try { - Stream fileStream = Files.walk(directory.toPath(), this.maxDepth, this.fileVisitOptions) - .skip(1) - .map(Path::toFile) - .filter(file -> !supportAcceptFilter - || ((AbstractFileListFilter) filter).accept(file)); + try (Stream pathStream = Files.walk(directory.toPath(), this.maxDepth, this.fileVisitOptions);) { + Stream fileStream = + pathStream + .skip(1) + .map(Path::toFile) + .filter(file -> !supportAcceptFilter + || ((AbstractFileListFilter) filter).accept(file)); if (supportAcceptFilter) { return fileStream.collect(Collectors.toList());