Skip to content

Commit

Permalink
Prevent concurrent modification of keysWithEvents map
Browse files Browse the repository at this point in the history
Fixes #86
which means
Fixes sbt/sbt#3687
Fixes sbt/sbt#3695
Fixes sbt/sbt#3775
  • Loading branch information
mechkg authored and dwijnand committed Nov 29, 2017
1 parent c280918 commit 6404741
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
7 changes: 6 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,10 @@ val io = (project in file("io"))
libraryDependencies ++= Seq(scalaCompiler.value % Test, scalaCheck % Test, scalatest % Test),
sourceManaged in (Compile, generateContrabands) := baseDirectory.value / "src" / "main" / "contraband-scala",
initialCommands in console += "\nimport sbt.io._, syntax._",
mimaPreviousArtifacts := Set(organization.value %% moduleName.value % "1.0.0")
mimaPreviousArtifacts := Set(organization.value %% moduleName.value % "1.0.0"),
mimaBinaryIssueFilters ++= Seq(
// MiMa doesn't understand private inner classes?
// method this(sbt.io.PollingWatchService,sbt.io.PollingWatchService#PollingThread,java.nio.file.Watchable,java.util.List)Unit in class sbt.io.PollingWatchService#PollingWatchKey does not have a correspondent in current version
exclude[DirectMissingMethodProblem]("sbt.io.PollingWatchService#PollingWatchKey.this"),
),
)
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 6404741

Please sign in to comment.