Skip to content

Commit

Permalink
Fix sbt#86: prevent concurrent modification of keysWithEvents map
Browse files Browse the repository at this point in the history
  • Loading branch information
mechkg committed Nov 29, 2017
1 parent 98cc14a commit c1ace4e
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions io/src/main/scala/sbt/io/PollingWatchService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class PollingWatchService(delay: FiniteDuration) extends WatchService {

override def register(path: JPath, events: WatchEvent.Kind[JPath]*): WatchKey = {
ensureNotClosed()
val key = new PollingWatchKey(thread, path, new java.util.ArrayList[WatchEvent[_]])
val key = new PollingWatchKey(path, new java.util.ArrayList[WatchEvent[_]])
keys += path -> key
watched += path -> events
key
Expand Down Expand Up @@ -158,14 +158,12 @@ class PollingWatchService(delay: FiniteDuration) extends WatchService {
}

private class PollingWatchKey(
origin: PollingThread,
override val watchable: Watchable,
val events: JList[WatchEvent[_]]
) extends WatchKey {
override def cancel(): Unit = ()
override def isValid(): Boolean = true
override def pollEvents(): java.util.List[WatchEvent[_]] = origin.keysWithEvents.synchronized {
origin.keysWithEvents -= this
override def pollEvents(): java.util.List[WatchEvent[_]] = {
val evs = new java.util.ArrayList[WatchEvent[_]](events)
events.clear()
evs
Expand Down

0 comments on commit c1ace4e

Please sign in to comment.