Fail early & more clearly on shaded-broken classfiles #21262
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 thejars and produce a classpath string:
Then I invoked
scalac
in the sbt shell, passing that classpath string:Using the two minisations in the 20405 and 20555 issues.
Fixes #20405
Fixes #20555