Menu

Your Java Dependencies Still Call sun.misc.Unsafe and the JDK Has Started Saying So
📰

Your Java Dependencies Still Call sun.misc.Unsafe and the JDK Has Started Saying So

DEV Community: java·Serguey Asael Shinder·9 days ago
#jN4a2Bru
#devtojava#devto#dev#warning#memory
Reading 0:00
15s threshold

You moved to Java 25,

mostly for the long term support.

The tests passed.

The service started.

And the first lines of the log

were not yours.

WARNING:

A terminally deprecated method

in sun.misc.Unsafe

has been called.

Then the name of a class

in a library you never chose,

three levels down

in the dependency tree.

Somebody filed a ticket

to silence the warning.

That is the wrong ticket.

sun.misc.Unsafe

was never a public API.

It is a back door into the JVM

that lets code read and write memory

directly,

with no bounds checks,

and for two decades

serialisers, buffer pools,

caches and fast collections

used it,

because nothing else was as fast.

Now there are proper replacements.

VarHandle, since Java 9,

for fields and arrays.

The Foreign Function and Memory API,

final since Java 22,

for memory outside the heap.

So the JDK is closing the door

in stages.

JDK 23 deprecated

the memory access methods

for removal.

JDK 24 started printing that warning

the first time one is…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.