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

Avoid name check when loading repl products #10253

Merged

Conversation

som-snytt
Copy link
Contributor

Supplying the name to defineClass means the name is checked, but if REPL found the class for a "translated" name, the name will never match. So REPL's class loader supplies null to mean DK. Some extra code could be added to preserve the translation and the name check, but for the REPL that might be unnecessary.

Fixes scala/bug#12705

@som-snytt som-snytt marked this pull request as ready for review January 3, 2023 19:48
@som-snytt
Copy link
Contributor Author

The stack trace in the test is jdk-specific. I will just remove that line; it showed that the loadClass fails the second time, but of course it does.

@som-snytt som-snytt force-pushed the issue/12705-repl-reflective-class-load branch from 6b755e1 to 70862c4 Compare January 3, 2023 21:48
private class TranslatingClassLoader(parent: ClassLoader) extends AbstractFileClassLoader(replOutput.dir, parent) {
override protected def findAbstractFile(name: String): AbstractFile = super.findAbstractFile(name) match {
case null if _initializeComplete => translateSimpleResource(name).map(super.findAbstractFile).orNull
case file => file
}
// if the name was mapped by findAbstractFile, supply null name to avoid name check in defineClass
override protected def findClass(name: String): Class[_] = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do super.findClass first and use the new code below only as a fallback?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I considered doing something fancy, but the class loader API is so complex already, plus ScalaClassLoader and AbstractFileClassLoader, and also throws, that I wasn't "up" for it.

I could imagine a boolean member called verifyDefiningName for AbstractFileClassLoader to consult.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A complex mix of complex ingredients, so I'm just generally worried about breaking stuff... I just saw now the AbstractFileClassLoader.findClass code that's overridden. In that light, LGTM.

@SethTisue SethTisue added this to the 2.13.11 milestone Jan 5, 2023
@lrytz lrytz enabled auto-merge January 6, 2023 10:46
@lrytz lrytz merged commit 91f0f66 into scala:2.13.x Jan 6, 2023
@som-snytt som-snytt deleted the issue/12705-repl-reflective-class-load branch January 6, 2023 18:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants