-
Notifications
You must be signed in to change notification settings - Fork 909
Description
Is your feature request related to a problem? Please describe.
As of Java 24 (released on March 18th, 2025), when running an application which uses the OpenTelemetry SDK, the following warning is logged at application startup:
WARNING: A terminally deprecated method in sun.misc.Unsafe has been called
WARNING: sun.misc.Unsafe::objectFieldOffset has been called by io.opentelemetry.internal.shaded.jctools.util.UnsafeAccess (file:/Users/thomas/.gradle/caches/modules-2/files-2.1/io.opentelemetry/opentelemetry-sdk-trace/1.48.0/e88429ab27db3fbb6ed579daf0ae5ceb98b70210/opentelemetry-sdk-trace-1.48.0.jar)
WARNING: Please consider reporting this to the maintainers of class io.opentelemetry.internal.shaded.jctools.util.UnsafeAccess
WARNING: sun.misc.Unsafe::objectFieldOffset will be removed in a future release
This is in line with the step-wise plan to completely remove access to sun.misc.Unsafe
in future Java versions. In particular, by default, Java 26 (March 2026) will fail the application at startup time if this internal API is used.
See more details and the complete plan here.
Describe the solution you'd like
The solution recommended by the Java team here.
Over the past several years, we have introduced two standard APIs that are safe and performant replacements for the memory-access methods in sun.misc.Unsafe:
java.lang.invoke.VarHandle, introduced in JDK 9 (JEP 193), provides methods to safely and efficiently manipulate on-heap memory, i.e., fields of objects, static fields of classes, and elements of arrays.
java.lang.foreign.MemorySegment, introduced in JDK 22 (JEP 454), provides methods to safely and efficiently access off-heap memory, sometimes in cooperation with VarHandle.
These standard APIs guarantee no undefined behavior, promise long-term stability, and have high-quality integration with the tooling and documentation of the Java Platform. (Examples of their use are given in JEP 471.) Given the availability of these APIs, it is now appropriate to deprecate and eventually remove the memory-access methods in sun.misc.Unsafe.
Describe alternatives you've considered
No other alternatives exist once sun.misc.Unsafe
is completely removed from the Java platform.
Additional context
Issue where a different usage of sun.misc.Unsafe
was introduced (different from what I get flagged in the warning): #6433. I can see the usage is behind a Java version check (<= 22), so the warning might not get printed out, but it's something to verify in this case. Perhaps an idea would be to produce multiple JARs when releasing the SDK, targeting different versions of Java. So that for Java 22+, the new FFM API can be used instead of sun.misc.Unsafe
.
And related issue about the problematic usage of sun.misc.Unsafe
: #6913