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

Fail early & more clearly on shaded-broken classfiles #21262

Merged
merged 1 commit into from
Jul 29, 2024

Conversation

dwijnand
Copy link
Member

The shading utility uses for the coursier or coursierapi classes has
removed the RuntimeVisibleAnnotation attribute after the ScalaSignature
attribute. Parsing such a classfile caused the Scala 3 compiler to
parse the file as a Java classfile. It seems there something about how
we deal with packages and package objects (which don't exist in Java)
when we are incorrectly sent down this code path. The Scala 2 compiler
already correctly caught and failed on this early, with this detail, so
look to do the same here.

Automating the test for this isn't easy. Because relying on an external
dependency would be a hazard for CI, long term. Perhaps we could try to
recreate a classfile with a similar bytecode problem, but that would be
quite involved as well. I guess we could commit some or all of the
classfiles from the original, but it's generally advised not to commit
binaries to the source repo.

So instead I'm leaving instructions as to how I manually tested this, in
preparing this change. I used coursier's cs binary to download the
jars and produce a classpath string:

 cs fetch -p org.scalameta:scalafmt-dynamic_2.13:3.8.1

Then I invoked scalac in the sbt shell, passing that classpath string:

scalac -classpath $classpathAbove i20405.scala
scalac -classpath $classpathAbove i20555.scala

Using the two minisations in the 20405 and 20555 issues.

Fixes #20405
Fixes #20555

The shading utility uses for the coursier or coursierapi classes has
removed the RuntimeVisibleAnnotation attribute after the ScalaSignature
attribute.  Parsing such a classfile caused the Scala 3 compiler to
parse the file as a Java classfile.  It seems there something about how
we deal with packages and package objects (which don't exist in Java)
when we are incorrectly sent down this code path.  The Scala 2 compiler
already correctly caught and failed on this early, with this detail, so
look to do the same here.

Automating the test for this isn't easy.  Because relying on an external
dependency would be a hazard for CI, long term.  Perhaps we could try to
recreate a classfile with a similar bytecode problem, but that would be
quite involved as well.  I guess we could commit some or all of the
classfiles from the original, but it's generally advised not to commit
binaries to the source repo.

So instead I'm leaving instructions as to how I manually tested this, in
preparing this change.  I used coursier's `cs` binary to download the
jars and produce a classpath string:

     cs fetch -p org.scalameta:scalafmt-dynamic_2.13:3.8.1

Then I invoked `scalac` in the sbt shell, passing that classpath string:

    scalac -classpath $classpathAbove i20405.scala
    scalac -classpath $classpathAbove i20555.scala

Using the two minisations in the 20405 and 20555 issues.
@dwijnand dwijnand marked this pull request as ready for review July 25, 2024 16:42
@dwijnand dwijnand requested a review from SethTisue July 25, 2024 16:42
@dwijnand dwijnand merged commit 4429d73 into scala:main Jul 29, 2024
28 checks passed
@dwijnand dwijnand deleted the crash-bc-of-shaded-scala2-classfiles branch July 29, 2024 16:59
WojciechMazur added a commit that referenced this pull request Aug 27, 2024
….5.2 (#21464)

Backports #21262 to the 3.5.2 branch.

PR submitted by the release tooling.
[skip ci]
@WojciechMazur WojciechMazur added this to the 3.5.2 milestone Oct 8, 2024
WojciechMazur added a commit that referenced this pull request Dec 3, 2024
…TS (#22083)

Backports #21262 to the 3.3.5.

PR submitted by the release tooling.
[skip ci]
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.

Loading coursier-interfaces crashes the compiler Compiler crash when importing coursierapi StringUtil
3 participants