Class java.lang.UnsupportedOperationException cannot be cast to class xsbti.FullReload
Asked Answered
G

5

7

I am trying to follow some tutorials to learn more about Scala and I am trying to use it in IntelliJ in my computer (MacBook Pro M1). I installed sdk using sdkman. However, I get certain errors regarding it and I don't know how to fix this.

EDIT: Following a suggestion below, more info about how I installed this:

I am trying the Introduction to Scala course on LinkedIn Learning. I installed the community version (Apple Sillicon) of IntelliJ available here, then Scala using the command curl -fL https://github.com/coursier/launchers/raw/master/cs-x86_64-apple-darwin.gz | gzip -d > cs && chmod +x cs && (xattr -d com.apple.quarantine cs || true) && ./cs setup available here. Finally, I used curl -s "https://get.sdkman.io" | bash and source "$HOME/.sdkman/bin/sdkman-init.sh" to install SDK, following what is available here.

After all that, the error below appears when I go into terminal and write sbt -version or if I try to run something in IntelliJ:

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')

I have no idea what this means and how to fix this. Could someone help me, please?

Grisette answered 15/8, 2022 at 5:6 Comment(5)
This is almost impossible for anyone to fix without knowing which exact steps did you take...we have no minimum exampleRemanent
Hi, @Dasph! Sorry for the lack of info. This is very new to me and I sincerely don't even know how to begin investigating it. I edited my question to include more info. Does that help to clarify what I did? Thanks a lot for your time!Grisette
see github.com/sbt/sbt/issues/6925Tesch
Hi, Seth! Thanks a lot. That seems to be my problem indeed. In your last comment there you mention that we should also update project/build.properties. Indeed, althought my sbt version is 1.7.1, my project/build.properties shows sbt.version = 1.5.5. How can I update those build.properties? Do I simply write there 1.7.1 in the place of the 1.5.5 and then I just reopen my project?Grisette
Yes, I simply wrote 1.7.1 in the place of 1.5.5, reopened my project and then it started to work! Thanks for the help!!Grisette
R
7

Already in the comments, but to post it as an answer:

The sbt version specified under project/build.properties should match your actual sbt version (you can get it by running $ sbt -version outside your project folder).

So edit project/build.properties accordingly:

sbt.version=1.9.3
Rostock answered 15/8, 2023 at 15:25 Comment(0)
T
3

You should control your java version. When i downgraded version to java 11 problem solved.

Trilobite answered 5/3, 2023 at 15:25 Comment(0)
S
2

In my case, the reason was in the JDK version. After this steps it works properly.

  1. Check the java version:
java -version
  1. Check all the JDK installed on your Mac:
/usr/libexec/java_home -V
  1. Update the version:
export JAVA_HOME=`/usr/libexec/java_home -v 1.8`

Source: http://lertsirikarn.blogspot.com/2022/05/how-to-fix-sbt-error-error-during-sbt.html

Scanner answered 31/1, 2023 at 18:16 Comment(0)
S
1

I believe the fundamental issue is, a newer SBT version will work with older versions of Java, but an older version of SBT won't work with a newer version of Java.

For example, you'll get the cannot be cast to class xsbti.FullReload error if your SBT version is 1.5.8 but you are using Java 21.

Most of the posts here do one of these options:

Option 1: increase the SBT version (probably the easiest option). For example, SBT 1.10.0 will work with Java 8, Java 21 and everything in between.

NOTE: To switch the SBT version, just change the config (file:project/build.properties value:sbt.version=x.x.x) . As I recall you don't need to manually update SBT as it will figure it out for you, just like it does for the scala version. You may get a bunch of deprecation warnings on your next build that you should fix.

Option 2: Downgrade your version of Java. You probably don't want to do this. However in my case I'm working on many projects, all with different versions of SBT and JAVA. I switched from a Java 21 project to a Java 8 project and didn't update my settings appropriately. There are few ways to switch the version, you may need to employ more than one:

  • change the default exe (i.e. sudo update-alternatives --config java and sudo update-alternatives --config javac)
  • update $JAVA_HOME (ex. export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64)
  • update your Intellij projects settings (ex: File->Project Structure->SDK)
  • update your build.sbt file (ex. add javaHome := Some(file("/usr/lib/jvm/java-21-openjdk-amd64")))
  • And more... depends on your environment, OS, and build system.
Spondylitis answered 16/5 at 1:16 Comment(0)
E
0

I was able to get it working by following this instructions from the repo xsbt

on the modifying SBT section stating,

If a project has project/build.properties defined, either delete the file or change sbt.version to 0.13.0-SNAPSHOT.

Equidistance answered 31/10, 2022 at 18:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.