Skip to content

runtime NoClassDefFoundError occurs on Scala 3.0.0, but not Scala 2.12, 2.13 #12396

Closed
@rtyley

Description

@rtyley

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:

image

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:

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions