-
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
Conversation
…replaced or mutated port of scala/scala@f6859f2
I think the build error is unrelated
|
//using propOrNone/getOrElse instead of propOrElse so that searchForBootClasspath is lazy evaluated | ||
def javaBootClassPath: String = propOrNone("sun.boot.class.path") getOrElse searchForBootClasspath |
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.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
This is not an improvement. propOrElse("user.dir", ???)
. This is the property that was removed at some point, I don't remember the details or naming. I see it is in JDK 8 but not now.
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.
oh, scala 2 at least supplied scala.boot.class.path
as a workaround.
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.
This is not an improvement
propOrElse
is not lazy like in scala2, right? So this was an improvement...
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.
That's a shame. Edit: I meant the usual lack of code sharing, not the improvement!
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.
@jtjeferreira Thanks!
retrying what I hope will prove to be a transient CI failure on Windows |
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 "" | ||
} |
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
def javaBootClassPath: String = propOrElse("sun.boot.class.path", "")
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 supply scala.boot.classpath
. Modern class loader hierarchy is quite different. I always use -nobootcp
in scala 2.
Thanks for merging this. You don't need nothing else from my side to backport this to other scala 3 branches, right? |
They all end up on out board and we port everything we can to the lts branch and will automatically be used for the next version. We will most likely have it in 3.3.6 and 3.6.4 |
(regardless, adding the "backport:nominated" label for extra assurance that it will be backported if at all possible. not actually sure if the label is looked at 😁 ) |
port of scala/scala@f6859f2 to fix sbt/sbt#7873