Skip to content

REPL class loader is context class loader #14293

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

Merged
merged 2 commits into from
Jan 25, 2022

Conversation

som-snytt
Copy link
Contributor

Fixes #14281

Also tweak the test mini-DSL to take context functions.

@griggt
Copy link
Contributor

griggt commented Jan 18, 2022

Also tweak the test mini-DSL to take context functions.

Thanks! I had been meaning to PR this.

@SethTisue
Copy link
Member

@som-snytt is there any possibility this was the way it was on purpose? do you see any downside to changing it to the Scala 2 way?

@som-snytt
Copy link
Contributor Author

@SethTisue the philosophical question is over my head, but

The context ClassLoader is provided by the creator of the thread for use by code running in this thread when loading classes and resources.

well, that is not clarifying.

I looked at ScriptEngine, and it just invokes ReplDriver.run and then Class.forName with the "REPL class loader" to fetch the result. The scripted invocation happens on an unknown thread, so restoring the context class loader is important. (Tests also use run.)

Is it reasonable to expect:

scala 2.13.8> class C
class C

scala 2.13.8> Thread.currentThread.getContextClassLoader.loadClass(classOf[C].getName)
val res0: Class[_] = class C

Another past use case (that people complain about) is service loading. One overload of ServiceLoader.load uses the context class loader.

@anatoliykmetyuk anatoliykmetyuk merged commit f0b70f1 into scala:master Jan 25, 2022
@som-snytt som-snytt deleted the issue/14281 branch January 25, 2022 15:56
@Kordyjan Kordyjan added this to the 3.1.2 milestone Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Scala 3 REPL does not appear to be loading resources properly
5 participants