java - 在 Java 9 中删除 sun.misc.Unsafe 将破坏 Spring、Hibernate

标签 java spring java-9 unsafe

我读过 here如果 Oracle 在 Java 9 中删除 sun.misc.Unsafe,Spring 和许多其他流行的库将会中断。但是,在 Spring 或 Hibernate 中没有对此类的静态引用。那么,这种说法是真的吗?

顺便说一句,Java 8 中有 64 个对 Unsafe 的引用,但如果 Oracle 删除了该类,他们将更新所有这些类,并且不会影响任何库(除非他们使用 Unsafe 直接就是)。

最佳答案

Mark Reinhold 在 2015 年 JVM 语言峰会上发表了题为 The Secret History and Tragic Fate of sun.misc.Unsafe 的演讲.尽管这些会谈有很多免责声明,但您可以在 10:23 上查看建议的方法。 ,在 JEP260 中有描述.

大体思路是:

  1. 用更安全、受支持的 API 替换现有功能
  2. 弃用已被替换的先前存在的 Unsafe API
  3. 在下一版本中删除已弃用的代码

以下是来自 JEP260 的一些相关文本(取自 2015 年 10 月 20 日):

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.

关于java - 在 Java 9 中删除 sun.misc.Unsafe 将破坏 Spring、Hibernate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31417320/

相关文章:

java - 如何删除默认边框以及如何锚定 jtable 的列标题?

java - 用 thymeleaf 添加 css

java - JPA 将另一个时间保存到数据库中

java - 如何通过将 --patch-module javac 选项传递给我的项目编译器,使 Eclipse 在 JDK 9+ 上编译修补模块? (见图)

Java 9 + Maven : What happens if two dependencies export the same module?

java - 如何让计数器在 while 循环中工作?

java - 手动向类文件添加方法调用?

java - 在 MySQL 中同时从不同客户端以同一用户身份登录是否安全?

Java Spring IOC bean创建值(value)

eclipse-plugin - Java 9 的 Eclipse Oxygen 插件功能导出失败