Skip to content

Avoid usage of sun.misc.Unsafe to prevent errors in future JDK releases #635

Open

Description

@sundrythoughts

The shaded Guava lib still uses sun.misc.Unsafe and in Java 25 we see the following warning:

WARNING: sun.misc.Unsafe::objectFieldOffset has been called by split.com.google.common.hash.Striped64 (file:/app/libs/java-client-4.18.4.jar)

According to the Guava project, you can use Guava-jre 33.4.8+ to avoid the warning and future errors.

https://openjdk.org/jeps/498

Description
We are deprecating and removing the memory-access methods in sun.misc.Unsafe in phases:

JDK 23 deprecated all of the memory-access methods for removal. This caused compile-time deprecation warnings for code that refers to the methods, alerting library developers to their forthcoming removal.

JDK 24 will, by default, issue a warning on the first occasion that any memory-access method is used, whether directly or via reflection. That is, it will issue at most one warning regardless of which memory-access methods are used and how many times any particular method is used. This will alert application developers and users to the forthcoming removal of the methods, and the need to upgrade libraries. An example of the warning is:

WARNING: A terminally deprecated method in sun.misc.Unsafe has been called
WARNING: sun.misc.Unsafe::setMemory has been called by com.foo.bar.Server (file:/tmp/foobarserver/thing.jar)
WARNING: Please consider reporting this to the maintainers of com.foo.bar.Server
WARNING: sun.misc.Unsafe::setMemory will be removed in a future release

JDK 26 or later will throw an exception whenever a memory-access method is used, whether directly or via reflection. This will further alert application developers and users to the imminent removal of the methods.

In releases after JDK 26, we will remove memory-access methods which have had standard replacements since JDK 9 (2017).

In releases after JDK 26, we will remove memory-access methods which have only had standard replacements since JDK 22 (2023).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions