-
Notifications
You must be signed in to change notification settings - Fork 21
Description
reproduction steps
Code for this issue can be found in https://github.com/rtyley/scala-2-vs-3-NoClassDefFoundError, relatively stripped down from where I actually encountered the issue when upgrading a library to Scala 3.0.0. The runtime error occurs when executing this code:
package object example { // Not using a package object allows Scala 3.0.0 to succeed
def useCompressUtils(): Unit = {
getClass // removing this allows Scala 3.0.0 to succeed.
// Fails under Scala 3.0.0 with "java.lang.NoClassDefFoundError: com/madgag/compress/CompressUtil$"
unzip(new ByteArrayInputStream(Array.emptyByteArray), createTempDirectory("example").toFile)
}
}When executing sbt test on the code, I get a java.lang.NoClassDefFoundError under Scala 3.0.0, but not under Scala 2.13.5 or 2.12.13. There is a Travis CI build to verify this:
The error given in sbt (an error report added to sbt with sbt/sbt#4602) suggests using a different ClassLoaderLayeringStrategy, however none of the available strategy settings (AllLibraryJars, Flat, ScalaLibrary) allow Scala 3.0.0 to succeed.
Scala 3.0.0 does pass if the code is modified in either of these ways:
- The call to
getClass(originally used to load test resources in the library where this issue was found) is removed. - The code is moved from a
package objectto a normalobject.
problem
I would expect the code compiled under Scala 3.0.0 to work just as well as Scala 2.12 or 2.13, without throwing a NoClassDefFoundError!
