-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Limit exposure to ConcurrentModificationException when sys props are replaced or mutated #22180
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
Comment on lines
+56
to
+57
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this change is a second commit, that is not part of the initial one that I was porting. But I think this improvement makes sense. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not an improvement. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh, scala 2 at least supplied There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's a shame. Edit: I meant the usual lack of code sharing, not the improvement! |
||
|
||
def javaExtDirs: String = propOrEmpty("java.ext.dirs") | ||
def scalaHome: String = propOrEmpty("scala.home") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to understand why this fallback exists, but I landed here and that was a dead end. Maybe we could just remove this code and do
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably? for now let's go with the tried-and-true
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see that this is what I asked in my other comment: it is because scala 2 runner supplied
scala.boot.class.path
. It would be worth revisiting what is supported under scala-cli. There is still-bootclasspath
option. In scala 2,-nobootcp
meant don't use-Xbootclasspath
and don't supplyscala.boot.classpath
. Modern class loader hierarchy is quite different. I always use-nobootcp
in scala 2.