From 9f425343ae6c19e30673b4a696a7db93783de577 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Wed, 25 May 2016 20:59:03 +0100 Subject: [PATCH] Make FileSystemWatcherTests thread-safe The list of changes is written to on one thread and read from on another. Without some form of sychronization this is not thread-safe. This commit makes changes a synchronized list which should guarantee that the reading thread can see the changes made by the writing thread. It also removes a redundant call to clear the list of changes at the start of waitsForPollingInterval. See gh-6038 --- .../boot/devtools/filewatch/FileSystemWatcherTests.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/filewatch/FileSystemWatcherTests.java b/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/filewatch/FileSystemWatcherTests.java index 5de4f54479..4b1885d6b8 100644 --- a/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/filewatch/FileSystemWatcherTests.java +++ b/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/filewatch/FileSystemWatcherTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2015 the original author or authors. + * Copyright 2012-2016 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. @@ -23,6 +23,7 @@ import java.io.FileOutputStream; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.HashSet; import java.util.LinkedHashSet; import java.util.List; @@ -56,7 +57,8 @@ public class FileSystemWatcherTests { private FileSystemWatcher watcher; - private List> changes = new ArrayList>(); + private List> changes = Collections + .synchronizedList(new ArrayList>()); @Rule public TemporaryFolder temp = new TemporaryFolder(); @@ -158,7 +160,6 @@ public class FileSystemWatcherTests { @Test public void waitsForPollingInterval() throws Exception { - this.changes.clear(); setupWatcher(100, 1); File folder = startWithNewFolder(); touch(new File(folder, "test1.txt"));