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

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

Closed
rtyley opened this issue May 16, 2021 · 4 comments
Closed

Comments

@rtyley
Copy link

rtyley commented May 16, 2021

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!

@dwijnand
Copy link
Member

Duplicate of scala/scala3#12249.

@smarter
Copy link
Member

smarter commented May 16, 2021

I don't think it's a duplicate, scala/scala3#12249 is about using the new export feature on Java code and that generating some incorrect code, whereas this issue is seemingly just about calling some Scala code and doesn't have anything to do with export. It does need to be minimized and re-opened in the dotty issue tracker though.

@SethTisue
Copy link
Member

@smarter as an aside, it would be nice to get lampepfl/dotty relocated to scala/* before toooooo much longer, one reason being so GitHub would let us transfer issues between there and scala/bug

@smarter
Copy link
Member

smarter commented May 17, 2021

@SethTisue agreed, but definitely not something I want to tackle myself :).

SethTisue added a commit to SethTisue/dotty that referenced this issue Jan 26, 2024
SethTisue added a commit to SethTisue/dotty that referenced this issue Jan 26, 2024
forward-port of scala/scala#10675 and scala/scala#8595
references scala/bug#12396 and scala/bug#11635
fixes scala#19527 ("bad constant pool tag 17")
also fixes unreported potential "bad constant pool tag 19" and
"bad constant pool tag 20" errors
SethTisue added a commit to scala/scala3 that referenced this issue Jan 30, 2024
forward-port of scala/scala#10675 and scala/scala#8595
references scala/bug#12396 and scala/bug#11635
fixes #19527 ("bad constant pool tag 17")
also fixes unreported potential "bad constant pool tag 19" and "bad constant pool tag 20" errors
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

No branches or pull requests

4 participants