Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport "Limit exposure to ConcurrentModificationException when sys props are replaced or mutated" to 3.6 #22275

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions compiler/src/dotty/tools/dotc/config/PathResolver.scala
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,25 @@ 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.
*/
def classPathEnv: String = envOrElse("CLASSPATH", "")
def sourcePathEnv: String = envOrElse("SOURCEPATH", "")

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

def javaExtDirs: String = propOrEmpty("java.ext.dirs")
def scalaHome: String = propOrEmpty("scala.home")
Expand Down
Loading