Skip to content

Commit

Permalink
Merge pull request #90 from dwijnand/fix-PollingWatchKey.pollEvents
Browse files Browse the repository at this point in the history
Prevent concurrent modification of keysWithEvents map
  • Loading branch information
dwijnand authored Dec 1, 2017
2 parents c280918 + 5c0db3b commit 4c3d042
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
9 changes: 7 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Dependencies._
// import com.typesafe.tools.mima.core._, ProblemFilters._
import com.typesafe.tools.mima.core._, ProblemFilters._

def baseVersion: String = "1.1.0"

Expand Down 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
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ abstract class SourceModificationWatchSpec(

IO.write(file, "foo")

watchTest(parentDir)(pollDelay, maxWait) {
IO.write(file, "bar")
}
// watchTest(parentDir)(pollDelay, maxWait) {
// IO.write(file, "bar")
// }
pending // until fixed https://github.com/sbt/io/issues/82
}

Expand Down

0 comments on commit 4c3d042

Please sign in to comment.