diff options
author | Som Snytt <som.snytt@gmail.com> | 2015-03-02 23:09:47 -0800 |
---|---|---|
committer | Som Snytt <som.snytt@gmail.com> | 2015-03-02 23:53:28 -0800 |
commit | 17caf79d158ca13776dff6d7461bba362b7a2f2f (patch) | |
tree | 509806eae49225f555fcb97efaade0fa29a4fc26 /test/files/run/t7775.scala | |
parent | 178e8df9b6a91375a6162721a0cbc2d90bcc7451 (diff) | |
download | scala-17caf79d158ca13776dff6d7461bba362b7a2f2f.tar.gz scala-17caf79d158ca13776dff6d7461bba362b7a2f2f.tar.bz2 scala-17caf79d158ca13776dff6d7461bba362b7a2f2f.zip |
SI-7775 Exclude nulls when iterating sys props
The previous fix to deal with concurrent modification of system
properties doesn't handle null results introduced when a property
is removed.
This commit filters nulls for safety, and also adds a `names`
method to `sys.SystemProperties`.
The test is upgraded.
Diffstat (limited to 'test/files/run/t7775.scala')
-rw-r--r-- | test/files/run/t7775.scala | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/test/files/run/t7775.scala b/test/files/run/t7775.scala index 48b0d89974..bc69064e17 100644 --- a/test/files/run/t7775.scala +++ b/test/files/run/t7775.scala @@ -1,3 +1,45 @@ +import scala.concurrent._, duration._ +import ExecutionContext.Implicits.global +import scala.tools.reflect.WrappedProperties.AccessControl._ +import java.util.concurrent.CyclicBarrier + +object Test extends App { + @volatile var done = false + val barrier = new CyclicBarrier(2) + + val probe = Future { + val attempts = 1024 // previously, failed after a few + def fail(i: Int) = s"Failed at $i" + barrier.await() + for (i <- 1 to attempts ; p <- systemProperties) + p match { case (k, v) => assert (k != null && v != null, fail(i)) } + } + probe onComplete { + case _ => done = true + } + + System.setProperty("foo", "fooz") + System.setProperty("bar", "barz") + barrier.await() // just for fun, wait to start mucking with properties + + // continually modify properties trying to break live iteration over sys props + // hint: don't iterate lively over sys props + var alt = true + while (!done) { + if (alt) { + System.getProperties.remove("foo") + System.setProperty("bar", "barz") + alt = false + } else { + System.getProperties.remove("bar") + System.setProperty("foo", "fooz") + alt = true + } + } + Await.result(probe, Duration.Inf) +} + +/* import scala.concurrent.{duration, Future, Await, ExecutionContext} import scala.tools.nsc.Settings import ExecutionContext.Implicits.global @@ -15,3 +57,4 @@ object Test { Await.result(compiler, duration.Duration.Inf) } } +*/ |