Skip to content

Commit 7513228

Browse files
committed
Address PR comments
* Improve `FileReadingMessageSource.setWatchEvents()` * Add `file.exists()` before adding file from event.
1 parent c6f69c2 commit 7513228

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

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

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.nio.file.WatchKey;
2929
import java.nio.file.WatchService;
3030
import java.nio.file.attribute.BasicFileAttributes;
31+
import java.util.Arrays;
3132
import java.util.Collection;
3233
import java.util.Comparator;
3334
import java.util.LinkedHashSet;
@@ -278,7 +279,10 @@ public void setUseWatchService(boolean useWatchService) {
278279
*/
279280
public void setWatchEvents(WatchEventType... watchEvents) {
280281
Assert.notEmpty(watchEvents, "'watchEvents' must not be empty.");
281-
this.watchEvents = watchEvents;
282+
Assert.noNullElements(watchEvents, "'watchEvents' must not contain null elements.");
283+
Assert.state(!this.running, "Cannot change watch events while running.");
284+
285+
this.watchEvents = Arrays.copyOf(watchEvents, watchEvents.length);
282286
}
283287

284288
@Override
@@ -495,12 +499,14 @@ private Set<File> filesFromEvents() {
495499
files.remove(file);
496500
}
497501
else {
498-
if (file.isDirectory()) {
499-
files.addAll(walkDirectory(file.toPath()));
500-
}
501-
else {
502-
files.remove(file);
503-
files.add(file);
502+
if (file.exists()) {
503+
if (file.isDirectory()) {
504+
files.addAll(walkDirectory(file.toPath()));
505+
}
506+
else {
507+
files.remove(file);
508+
files.add(file);
509+
}
504510
}
505511
}
506512
}

0 commit comments

Comments
 (0)