Skip to content

Commit

Permalink
Limit exposure to ConcurrentModificationException when sys props are …
Browse files Browse the repository at this point in the history
…replaced or mutated

port of scala/scala@f6859f2
  • Loading branch information
jtjeferreira committed Dec 10, 2024
1 parent 1775d0b commit 705c33c
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions compiler/src/dotty/tools/dotc/config/PathResolver.scala
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,16 @@ object PathResolver {
/** Values found solely by inspecting environment or property variables.
*/
object Environment {
private def searchForBootClasspath = (
systemProperties find (_._1 endsWith ".boot.class.path") map (_._2) getOrElse ""
)
private def searchForBootClasspath = {
import scala.jdk.CollectionConverters.*
val props = System.getProperties
// This formulation should be immune to ConcurrentModificationExceptions when system properties
// we're unlucky enough to witness a partially published result of System.setProperty or direct
// mutation of the System property map. stringPropertyNames internally uses the Enumeration interface,
// rather than Iterator, and this disables the fail-fast ConcurrentModificationException.
val propNames = props.stringPropertyNames()
propNames.asScala collectFirst { case k if k endsWith ".boot.class.path" => props.getProperty(k) } getOrElse ""
}

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

0 comments on commit 705c33c

Please sign in to comment.