From 9d5ed33ef9b503f20506dbe3e410960069a99d0a Mon Sep 17 00:00:00 2001 From: Jason Zaugg Date: Fri, 23 Aug 2013 09:29:56 +0200 Subject: SI-7775 Harden against the shifting sands of System.getProperties If another thread writes a new system property (which can happen in pretty innocuous code such as `new Date`!), the compiler startup could fail with a `ConcurrentModificationException` as it iterated all bindings in the properties map in search of a boot classpath property for esoteric JVMs. This commit uses `Properties#getStringProperties` to get a snapshot of the keys that isn't backed by the live map, and iterates these instead. That method will also limit us to bindings with String values, which is all that we expect. --- test/files/run/t7775.scala | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 test/files/run/t7775.scala (limited to 'test/files/run') diff --git a/test/files/run/t7775.scala b/test/files/run/t7775.scala new file mode 100644 index 0000000000..5fb0327611 --- /dev/null +++ b/test/files/run/t7775.scala @@ -0,0 +1,17 @@ +import scala.concurrent.{duration, future, Await, ExecutionContext} +import scala.tools.nsc.Settings +import ExecutionContext.Implicits.global + +// Was failing pretty regularly with a ConcurrentModificationException as +// WrappedProperties#systemProperties iterated directly over the mutable +// global system properties map. +object Test { + def main(args: Array[String]) { + val tries = 1000 // YMMV + val compiler = future { + for(_ <- 1 to tries) new Settings(_ => {}) + } + for(i <- 1 to tries * 10) System.setProperty(s"foo$i", i.toString) + Await.result(compiler, duration.Duration.Inf) + } +} -- cgit v1.2.3