Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent concurrent modification of keysWithEvents map #90

Merged
merged 2 commits into from
Dec 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You wrap it as a block I think 😊

pendingUntilFixed {
  watchTest(parentDir)(pollDelay, maxWait) {
    IO.write(file, "bar")
  }
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah! Cheers.

}

Expand Down