dd-trace-java icon indicating copy to clipboard operation
dd-trace-java copied to clipboard

JVM 25 warning - remove usage of sun.misc.Unsafe

Open der-eismann opened this issue 2 months ago • 3 comments

Tracer Version(s)

1.53.0

Java Version(s)

25.0.0

JVM Vendor

Amazon Corretto

Bug Report

We are starting to use Java 25 with a bunch of projects and saw this warning block at the top of the output:

WARNING: A terminally deprecated method in sun.misc.Unsafe has been called
WARNING: sun.misc.Unsafe::objectFieldOffset has been called by net.bytebuddy.dynamic.loading.ClassInjector$UsingUnsafe$Dispatcher$CreationAction (file:/usr/local/datadog-agent.jar)
WARNING: Please consider reporting this to the maintainers of class net.bytebuddy.dynamic.loading.ClassInjector$UsingUnsafe$Dispatcher$CreationAction
WARNING: sun.misc.Unsafe::objectFieldOffset will be removed in a future release

I think this is similar to https://github.com/open-telemetry/opentelemetry-java-instrumentation/issues/13375, would be nice if we could get rid of this warning and make the agent future proof. Maybe this is even coming from OpenTelemetry directly, feel free to close this issue then.

Expected Behavior

No warning during startup

Reproduction Code

No response

der-eismann avatar Oct 07 '25 09:10 der-eismann

I just saw that there's also this warning:

WARNING: A restricted method in java.lang.System has been called
WARNING: java.lang.System::load has been called by com.kenai.jffi.internal.StubLoader in an unnamed module (file:/usr/local/datadog-agent.jar)
WARNING: Use --enable-native-access=ALL-UNNAMED to avoid a warning for callers in this module
WARNING: Restricted methods will be blocked in a future release unless native access is enabled

Let me know if I should create a separate issue for this.

der-eismann avatar Oct 07 '25 09:10 der-eismann

Hi @der-eismann note the reference to Byte-Buddy won't happen with 1.54.0

However, you will see the following:

WARNING: A terminally deprecated method in sun.misc.Unsafe has been called
WARNING: sun.misc.Unsafe::objectFieldOffset has been called by datadog.jctools.util.UnsafeAccess (file:/Users/stuart.mcculloch/tracers/dd-java-agent-1.54.0.jar)

This is because the Java 25 JVM only reports the first use of sun.misc.Unsafe it finds - so although we addressed the initial Byte-Buddy reference, it now reports a reference found in the embedded jctools library (used to provide high-performance queues inside the tracer.)

mcculls avatar Oct 07 '25 09:10 mcculls

That's good to hear, thanks for the quick reply! Our auto-updater didn't notify us of 1.54.0 yet, sorry about that. I assume it will be worked on one warning at a time 🙂 I changed the issue title, feel free to change again or close this issue.

der-eismann avatar Oct 07 '25 09:10 der-eismann