Skip to content

Commit 7a1c473

Browse files
jtjeferreiratgodzik
authored andcommitted
Limit exposure to ConcurrentModificationException when sys props are replaced or mutated
port of scala/scala@f6859f2 [Cherry-picked 705c33c]
1 parent 3ca075f commit 7a1c473

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

Diff for: compiler/src/dotty/tools/dotc/config/PathResolver.scala

+10-3
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,16 @@ object PathResolver {
3636
/** Values found solely by inspecting environment or property variables.
3737
*/
3838
object Environment {
39-
private def searchForBootClasspath = (
40-
systemProperties find (_._1 endsWith ".boot.class.path") map (_._2) getOrElse ""
41-
)
39+
private def searchForBootClasspath = {
40+
import scala.jdk.CollectionConverters.*
41+
val props = System.getProperties
42+
// This formulation should be immune to ConcurrentModificationExceptions when system properties
43+
// we're unlucky enough to witness a partially published result of System.setProperty or direct
44+
// mutation of the System property map. stringPropertyNames internally uses the Enumeration interface,
45+
// rather than Iterator, and this disables the fail-fast ConcurrentModificationException.
46+
val propNames = props.stringPropertyNames()
47+
propNames.asScala collectFirst { case k if k endsWith ".boot.class.path" => props.getProperty(k) } getOrElse ""
48+
}
4249

4350
/** Environment variables which java pays attention to so it
4451
* seems we do as well.

0 commit comments

Comments
 (0)