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

sbt 1.6.2 on OpenJDK 18 is broken #6925

Closed
tribbloid opened this issue Jun 13, 2022 · 25 comments
Closed

sbt 1.6.2 on OpenJDK 18 is broken #6925

tribbloid opened this issue Jun 13, 2022 · 25 comments
Assignees
Labels
area/jdk_x jdk 9, 10, 11, 17 etc Bug help wanted

Comments

@tribbloid
Copy link

steps

  • checkout any sbt project
  • run sbt compile

problem

java.lang.ClassCastException: class java.lang.UnsupportedOperationException cannot be cast to class xsbti.FullReload (java.lang.UnsupportedOperationException is in module java.base of loader 'bootstrap'; xsbti.FullReload is in unnamed module of loader 'app')
	at sbt.internal.XMainConfiguration.run(XMainConfiguration.java:59)
	at sbt.xMain.run(Main.scala:46)
	at xsbt.boot.Launch$.$anonfun$run$1(Launch.scala:149)
	at xsbt.boot.Launch$.withContextLoader(Launch.scala:176)
	at xsbt.boot.Launch$.run(Launch.scala:149)
	at xsbt.boot.Launch$.$anonfun$apply$1(Launch.scala:44)
	at xsbt.boot.Launch$.launch(Launch.scala:159)
	at xsbt.boot.Launch$.apply(Launch.scala:44)
	at xsbt.boot.Launch$.apply(Launch.scala:21)
	at xsbt.boot.Boot$.runImpl(Boot.scala:78)
	at xsbt.boot.Boot$.run(Boot.scala:73)
	at xsbt.boot.Boot$.main(Boot.scala:21)
	at xsbt.boot.Boot.main(Boot.scala)
[error] [launcher] error during sbt launcher: java.lang.ClassCastException: class java.lang.UnsupportedOperationException cannot be cast to class xsbti.FullReload (java.lang.UnsupportedOperationException is in module java.base of loader 'bootstrap'; xsbti.FullReload is in unnamed module of loader 'app')

expectation

should compile project without error

notes

observed on Pop_OS 22.04.

Java version:

$ java --version
openjdk 18-ea 2022-03-22
OpenJDK Runtime Environment (build 18-ea+36-Ubuntu-1)
OpenJDK 64-Bit Server VM (build 18-ea+36-Ubuntu-1, mixed mode, sharing)

@tribbloid tribbloid added the Bug label Jun 13, 2022
@SethTisue
Copy link
Member

You're using an early-access build of JDK 18. Does the same thing occur in a final-release build?

fwiw, I'm on JDK 18 final (Eclipse Adoptium Java 18.0.1) on MacOS and sbt 1.6.2 works fine for me.

@eed3si9n
Copy link
Member

Yea it worked last time I checked on macOS
https://twitter.com/eed3si9n/status/1530594366401794051?s=21&t=hg6TWFbxHePiBzMLaNJPzg

@zmerr
Copy link

zmerr commented Jun 17, 2022

I have the same problem 😔
How did you manage to solve the problem?

@eed3si9n
Copy link
Member

@zmerr I am not sure what the repro steps are here. It worked with the latest Eclipse Temurin on Mac. What operating system and JDK are you using?

@zmerr
Copy link

zmerr commented Jun 17, 2022

@eed3si9n I have MacOS
And I was using
openjdk 18.0.1 2022-04-19

I had the same problem with
openjdk version "18.0.1.1" 2022-04-22

installed through brew

But it was workin on all the projects, except one which had
dockerBaseImage := "adoptopenjdk:15-jre-hotspot”,
in the build file.

So as a silly temporary fix, I just removed java 18 and installed adoptopenjdk15, instead.
And it started working.

But this is not a real solution, because effectively this broke everything else that was supposed to work on java 18.

@zmerr
Copy link

zmerr commented Jun 17, 2022

You're using an early-access build of JDK 18. Does the same thing occur in a final-release build?

fwiw, I'm on JDK 18 final (Eclipse Adoptium Java 18.0.1) on MacOS and sbt 1.6.2 works fine for me.

mine was not working with openjdk 18.0.1 2022-04-19
what could possibly be wrong with it?
Any help would be appreciated.

@eed3si9n eed3si9n added the area/jdk_x jdk 9, 10, 11, 17 etc label Jun 17, 2022
@eed3si9n eed3si9n changed the title sbt 1.6.2 on Java 18 is broken sbt 1.6.2 on OpenJDK 18 is broken Jun 17, 2022
@xiaoyureed
Copy link

I met the same problem with jdk18.0.1.1.
Jdk17.0.1 works well with sbt.

@eed3si9n
Copy link
Member

I am guessing that this is coming from the following code in the launcher https://github.com/sbt/launcher/blob/605b67814f4f1a2ed6ddd46213ffec8e8e58ec2e/launcher-implementation/src/main/scala/xsbt/boot/Launch.scala#L148-L150:

      try {
        withContextLoader(appProvider.loader)(main.run(appConfig))
      } catch { case e: xsbti.FullReload => if (e.clean) delete(launcher.bootDirectory); throw e }

Did something change in JDK 18 that's preventing a pattern match written in Scala?
Someone who is more interested in figuring this out could dig deeper.

@valentin-panalyt
Copy link

valentin-panalyt commented Jun 27, 2022

Seeing the same error on sbt.version=1.5.8 and

openjdk version "18.0.1.1" 2022-04-22
OpenJDK Runtime Environment Homebrew (build 18.0.1.1+0)
OpenJDK 64-Bit Server VM Homebrew (build 18.0.1.1+0, mixed mode, sharing)

Can confirm that it doesn't appear with jdk 17.

@SethTisue
Copy link
Member

It would help if we had the stack trace for the underlying java.lang.UnsupportedOperationException

@SethTisue
Copy link
Member

SethTisue commented Jun 28, 2022

I put out a call for assistance at https://twitter.com/SethTisue/status/1541822426203291648

what we need is a way to reproduce the problem. for example, is anyone able to make it happen in a GitHub Actions run in a public GitHub repo?

are any of you able to make it happen in a brand new, empty user account on a MacOS machine? (or any other OS?) if so, can you share steps?

@zmerr
Copy link

zmerr commented Jun 28, 2022

Mine is reproducible when this is in the build file:

    dockerBaseImage := "adoptopenjdk:15-jre-hotspot”,

@eed3si9n
Copy link
Member

What happens if you change JRE to JDK?

@Zamirk
Copy link

Zamirk commented Jun 29, 2022


java.lang.ClassCastException: class java.lang.UnsupportedOperationException cannot be cast to class xsbti.FullReload (java.lang.UnsupportedOperationException is in module java.base of loader 'bootstrap'; xsbti.FullReload is in unnamed module of loader 'app')
	at sbt.internal.XMainConfiguration.run(XMainConfiguration.java:59)
	at sbt.xMain.run(Main.scala:46)
	at xsbt.boot.Launch$.$anonfun$run$1(Launch.scala:149)
	at xsbt.boot.Launch$.withContextLoader(Launch.scala:176)
	at xsbt.boot.Launch$.run(Launch.scala:149)
	at xsbt.boot.Launch$.$anonfun$apply$1(Launch.scala:44)
	at xsbt.boot.Launch$.launch(Launch.scala:159)
	at xsbt.boot.Launch$.apply(Launch.scala:44)
	at xsbt.boot.Launch$.apply(Launch.scala:21)
	at xsbt.boot.Boot$.runImpl(Boot.scala:78)
	at xsbt.boot.Boot$.run(Boot.scala:73)
	at xsbt.boot.Boot$.main(Boot.scala:21)
	at xsbt.boot.Boot.main(Boot.scala)
[error] [launcher] error during sbt launcher: java.lang.ClassCastException: class java.lang.UnsupportedOperationException cannot be cast to class xsbti.FullReload (java.lang.UnsupportedOperationException is in module java.base of loader 'bootstrap'; xsbti.FullReload is in unnamed module of loader 'app')


Mac intel chip.
Seems to have occurred for a colleague after installing the latest openjdk through brew.

@adpi2 adpi2 self-assigned this Jul 6, 2022
@adpi2
Copy link
Member

adpi2 commented Jul 6, 2022

I managed to reproduce this issue on sbt 1.5.8, on Window, Mac, Ubuntu and many different Java 18 implementations.

But as soon as I bump to sbt 1.6.0, the problem disappears. Same if I use Java 17, no crash. The result of this investigation can be found here. I tested it also on Mac M1 and I have the exact same behavior.

Still, I am a bit surprised by the title of this issue sbt 1.6.2 on OpenJDK 18 because all my attempt to run sbt 1.6.2 on OpenJDK 18 succeeded. In addition the cast in class java.lang.UnsupportedOperationException cannot be cast to class xsbti.FullReload has been removed in sbt 1.6.0: 39bcfee

So I am quite sure now that this bug only happens on sbt 1.5.8 and there is a fix in sbt 1.6.0 that we can backport.

@adpi2
Copy link
Member

adpi2 commented Jul 6, 2022

Here is the fix: https://github.com/adpi2/sbt/tree/fix-JDK-18

But there is no branch 1.5.x anymore in sbt so I guess that means 1.5 is EOL.

The solution is to upgrade your build to 1.6.2.

@adpi2
Copy link
Member

adpi2 commented Jul 6, 2022

Please reopen this issue if I am wrong and the same error appears on sbt 1.6.x.

@adpi2 adpi2 closed this as completed Jul 6, 2022
@eed3si9n
Copy link
Member

eed3si9n commented Jul 6, 2022

Thanks for the investigation @adpi2!

@jab701
Copy link

jab701 commented Jul 17, 2022

I am having this problem with SBT 1.7.1 & openJDK 18. I am running MacOS (Apple M1) and installed SBT via brew.

I am trying to run chisel...

@adpi2
Copy link
Member

adpi2 commented Jul 18, 2022

In chipsalliance/chisel3, the version of sbt is still 1.5.8, that's why it does not work.

https://github.com/chipsalliance/chisel3/blob/master/project/build.properties

@JulianBailey
Copy link

Ah okay, the MacOS instructions I was following just said to "brew install sbt" it never specified a particluar version. Thanks for your help, I will try this out.

@som-snytt
Copy link
Contributor

I just hit this because https://github.com/coursier/interface is on 1.5.8. Maybe there is a way to advertise the limitation.

Or hold a spree just for upgrading the entire ecosystem to 1.7.1. Or one day in which Scala Steward gets merge rights on every repository.

@SethTisue
Copy link
Member

For those visiting this ticket who may be relatively new to sbt: it's important to understand that when you run sbt, the version that runs is determined by the project/build.properties file in your current directory, if it exists, rather than by the sbt version you have installed.

Thus: Even if you've installed sbt 1.6 or 1.7 on your system, you may still need to update project/build.properties, too.

kitbellew added a commit to kitbellew/metaconfig that referenced this issue Aug 11, 2022
Can't build with java 18 otherwise (sbt/sbt#6925).
kitbellew added a commit to scalameta/metaconfig that referenced this issue Aug 11, 2022
Can't build with java 18 otherwise (sbt/sbt#6925).
eikel added a commit to eikel/flink-scala-3 that referenced this issue Aug 18, 2022
It is the latest version and fixes building on JDK 18.
See sbt/sbt#6925
sjwiesman pushed a commit to sjwiesman/flink-scala-3 that referenced this issue Aug 18, 2022
It is the latest version and fixes building on JDK 18.
See sbt/sbt#6925
@tianday66
Copy link

@adpi2 Thanks a lot for your help! I have tried to fix this problem for about an hour and finally solved it in a minute with your help!

@manojnpalat
Copy link

here

Thanks @SethTisue and @adpi2 - being a newbie to scala, these were great timesavers for me - worked like a charm.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area/jdk_x jdk 9, 10, 11, 17 etc Bug help wanted
Projects
None yet
Development

No branches or pull requests