Question About unfamiliar behavior

Hi, i started learning Scala and i was enjoying the theory behind it, then i encountered this Warning about LazyVals$:

WARNING: A terminally deprecated method in sun.misc.Unsafe
has been called
WARNING: sun.misc.Unsafe::objectFieldOffset has been called
by scala.runtime.LazyVals$ (file:/home/haitam/.cache/cours
ier/arc/https/github.com/scala/scala3/releases/download/3.8
.3/scala3-3.8.3-x86_64-pc-linux.tar.gz/scala3-3.8.3-x86_64-
pc-linux/maven2/org/scala-lang/scala-library/3.8.3/scala-li
brary-3.8.3.jar)
WARNING: Please consider reporting this to the maintainers
of class scala.runtime.LazyVals$
WARNING: sun.misc.Unsafe::objectFieldOffset will be removed
in a future release

Note : it’s not a problem for me, but im just trying to understand the reason behind it

Thanks.

Hmm. Not my area of expertise, but this smells like a JVM compatibility issue. What version of the JVM are you running on?

1 Like

It’s a known thing, don’t worry about it. Happens to me too, any time I use the REPL (I have JVM 24). There is some info here. Basically newer JVM versions restrict sun.misc.unsafe and Scala 3.9 onward will have a new lazy val implementation that won’t use it. Until then we’ll keep seeing the annoying warning :smiley:

I can confirm that the warning is harmless and can be ignored. The Scala 3 team is working on eliminating it.

This is already an FAQ and we’re overdue to properly document the situation. (In addition to the 3.8 release notes, there are various tickets about it, such as Runtime code implementing lazy val should not use sun.misc.Unsafe on Java 9+ (JEP-471) · Issue #9013 · scala/scala3 · GitHub, but it’s too much to expect users to find those tickets and read the discussions on them.)

I will add some remarks about it to the JDK Compatibility page (JDK Compatibility | Scala Documentation) and also to the Scala FAQ (Scala FAQ | Scala Documentation), and I’ll report back here when I’ve done so.

1 Like