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

correctly fix NoClassDefFoundError in sbt bridge #10966

Merged
merged 1 commit into from
Jan 6, 2025

Conversation

SethTisue
Copy link
Member

@SethTisue SethTisue commented Dec 22, 2024

adjustment to #10964 cc @Friendseeker

@scala-jenkins scala-jenkins added this to the 2.13.17 milestone Dec 22, 2024
@SethTisue SethTisue added the prio:blocker release blocker (used only by core team, only near release time) label Dec 22, 2024
@SethTisue SethTisue modified the milestones: 2.13.17, 2.13.16 Dec 22, 2024
@SethTisue SethTisue self-assigned this Dec 22, 2024
@SethTisue
Copy link
Member Author

SethTisue commented Dec 23, 2024

Oh, I hadn't understood the code sufficiently — there are three possible outcomes here (success, ClassCastException, and NoClassDefFoundError), not just two. Further adjustment made.

But actually I don't really understand the circumstances under which the ClassCastException occurs, is that expected to you @Friendseeker @lrytz?

@Friendseeker
Copy link
Contributor

Oh, I hadn't understood the code sufficiently — there are three possible outcomes here (success, ClassCastException, and NoClassDefFoundError), not just two. Further adjustment made.

But actually I don't really understand the circumstances under which the ClassCastException occurs, is that expected to you @Friendseeker @lrytz?

I don't know either. Only thing I know is that both Scala 2 and Scala 3 compiler checks for NoClassDefFoundError.

Scala 2:

lazy val callback2 =
try callback.asInstanceOf[AnalysisCallback2]
catch { case _: NoClassDefFoundError => null}

Scala 3:
https://github.com/scala/scala3/blob/d50973b3d3f00080054ff7c08eb9a319c8d1b6de/sbt-bridge/src/dotty/tools/xsbt/CompilerBridgeDriver.java#L144-L157

If we trust the Java documentation, ClassCastException only happens if JVM actually finds the class being casted to, then determines if the cast is invalid.

@SethTisue
Copy link
Member Author

aha, in the context of the JUnit test that was failing, callback is a scala.tools.xsbt.TestCallback

TestCallback currently extends AnalysisCallback2. if I change it to extend AnalysisCallback3, then:

[error] Missing implementations for 2 members of trait AnalysisCallback3.
[error]   def getSourceInfos(): xsbti.compile.analysis.ReadSourceInfos = ???
[error]   def toVirtualFile(x$1: java.nio.file.Path): xsbti.VirtualFile = ???
[error] class TestCallback extends AnalysisCallback3 {
[error]       ^

@Friendseeker should we push that change through? it appears you did something similar in sbt/zinc#1306, where we see:

-class TestCallback extends AnalysisCallback2 {
+class TestCallback extends AnalysisCallback3 {

@Friendseeker
Copy link
Contributor

Friendseeker commented Dec 23, 2024

aha, in the context of the JUnit test that was failing, callback is a scala.tools.xsbt.TestCallback

TestCallback currently extends AnalysisCallback2. if I change it to extend AnalysisCallback3, then:


[error] Missing implementations for 2 members of trait AnalysisCallback3.

[error]   def getSourceInfos(): xsbti.compile.analysis.ReadSourceInfos = ???

[error]   def toVirtualFile(x$1: java.nio.file.Path): xsbti.VirtualFile = ???

[error] class TestCallback extends AnalysisCallback3 {

[error]       ^

@Friendseeker should we push that change through? it appears you did something similar in sbt/zinc#1306, where we see:

-class TestCallback extends AnalysisCallback2 {

+class TestCallback extends AnalysisCallback3 {

Yes. I definitely think we should push the change in TestCallback to keep things in sync.

@SethTisue SethTisue added the internal not resulting in user-visible changes (build changes, tests, internal cleanups) label Jan 6, 2025
@SethTisue
Copy link
Member Author

labeling "internal" since the problem this fixes never shipped.

@SethTisue SethTisue merged commit cb415ba into scala:2.13.x Jan 6, 2025
1 of 3 checks passed
@SethTisue SethTisue deleted the re-fix-sbt-bridge branch January 6, 2025 21:44
@SethTisue
Copy link
Member Author

heh, I meant to just enable auto-merge once CI liked it, but I apparently fat-fingered that

I already did junit/test locally, but regardless, I will check the Jenkins job and the nightly GitHub Actions jobs before announcing the new release candidate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
internal not resulting in user-visible changes (build changes, tests, internal cleanups) prio:blocker release blocker (used only by core team, only near release time)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants