Skip to content

Commit 3904bda

Browse files
authored
Merge pull request #158 from scala/backport-lts-3.3-22180
Backport "Limit exposure to ConcurrentModificationException when sys props are replaced or mutated" to 3.3 LTS
2 parents 23b0e40 + 5a42fb4 commit 3904bda

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

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

+12-4
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,25 @@ 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.
4552
*/
4653
def classPathEnv: String = envOrElse("CLASSPATH", "")
4754
def sourcePathEnv: String = envOrElse("SOURCEPATH", "")
4855

49-
def javaBootClassPath: String = propOrElse("sun.boot.class.path", searchForBootClasspath)
56+
//using propOrNone/getOrElse instead of propOrElse so that searchForBootClasspath is lazy evaluated
57+
def javaBootClassPath: String = propOrNone("sun.boot.class.path") getOrElse searchForBootClasspath
5058

5159
def javaExtDirs: String = propOrEmpty("java.ext.dirs")
5260
def scalaHome: String = propOrEmpty("scala.home")

0 commit comments

Comments
 (0)