Java Cup
Inside Java

News and views from members of the Java team at Oracle

The Secret History and Tragic Fate of sun.misc.Unsafe

(Recorded at JVMLS 2015 - for more, check our JVMLS 2015 playlist.)

sun.misc.Unsafe began as an internal bridge between the JVM and Java libraries, supporting reflection, serialization, direct buffers, and concurrency. Its adoption outside the JDK enabled fast libraries and new abstractions, but also created security risks, maintenance burdens, and dependencies on an unsupported API that applications could inherit unknowingly.

Mark Reinhold explains the JDK 9 encapsulation plan described in JEP 260, including continued access to Unsafe while supported alternatives are developed. The proposed migration strategy replaces widely used operations with safer APIs before restricting them. The discussion weighs compatibility, explicit access to internals, and the difficulty of changing entrenched library dependencies.