Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removal of sun.misc.Unsafe in Java 9 will break Spring, Hibernate

I read here that Spring and many other popular libraries will break if Oracle removes sun.misc.Unsafe in Java 9. However, there are no static references to this class in Spring or Hibernate. So, is that claim true?

BTW there are 64 references to Unsafe in Java 8, but if Oracle removes that class they will update all of them and no library will be affected (unless they use Unsafe directly that is).

like image 785
Lluis Martinez Avatar asked Jul 14 '15 21:07

Lluis Martinez


2 Answers

Mark Reinhold had a talk during JVM Language Summit 2015 titled The Secret History and Tragic Fate of sun.misc.Unsafe. Although these talks have plenty of disclaimers on them, you can see the proposed approach at 10:23, which is described in JEP260.

The general idea is:

  1. replace existing functionality with safer, supported APIs
  2. deprecate the previously existing Unsafe APIs that has been replaced
  3. remove the deprecated code in the next version

Here is some relevant text from JEP260 (taken from October 20th 2015):

In JDK 9 we propose to:

  • Encapsulate all non-critical internal APIs by default: The modules that define them will not export their packages for outside use. (Access to such APIs will be available, as a last resort, via a command-line flag at both compile time and run time, unless those APIs are revised or removed for other reasons.)

  • Encapsulate critical internal APIs for which supported replacements exist in JDK 8, in the same manner and with the same last-resort workaround. (A supported replacement is one that is either part of the Java SE 8 standard (i.e., in a java.* or javax.* package) or else JDK-specific and annotated with @jdk.Exported (typically in a com.sun.* or jdk.* package).)

  • Not encapsulate critical internal APIs for which supported replacements do not exist in JDK 8 and, further, deprecate those which have supported replacements in JDK 9 with the intent to encapsulate them, or possibly even remove them, in JDK 10.

...

Critical internal APIs for which replacements are introduced in JDK 9 will be deprecated in JDK 9 and either encapsulated or removed in JDK 10.

like image 51
mkobit Avatar answered Sep 23 '22 14:09

mkobit


Maybe the references are not in the core of Spring or Hibernate, but somewhere else. The document linked says with regard to Spring

Spring Framework (via Objenesis, with a fallback)

I tried to search for usages of Unsafe in the project I am currently working on, so there are still quite some libraries which may break.

result of quick search:

  • Guava
  • GWT
  • Netty
  • Jersey-Common
  • Infinispan
  • Jboss-Modules
like image 45
user140547 Avatar answered Sep 22 '22 14:09

user140547