JavaLangAccess and SharedSecrets in Java 9

It seems that the SharedSecrets and JavaLangAccess from sun.misc have been removed in Java 9.

Are there any replacements in Java 9 for the functionality provided by these classes?

+7
java java-9
source share
2 answers

Both of the above classes are packaged in the jdk.internal.misc package.

One of the ways you can try to access them is to use the option

 --add-exports <source-module>/<package>=<target-module>(,<target-module>)* 

for your use case:

 --add-exports java.base/jdk.internal.misc=your.module 

Note : - Waiver of JEP-261: Module System -

The --add-exports and --add-opens options should be used with great care. You can use them to access the internal library API by the module or even the JDK itself, but you do so at your own risk: if this internal API is changed or deleted, then your library or application will not be executed.

+5
source share

According to Error # JDK-8137056

In preparation for JEP 160, SharedSecrets and friend interfaces should be moved from "sun.misc" and located in a truly closed package

And now they are available at jdk.internal.misc

Move SharedSecrets and Friends to jdk.internal.misc

+1
source share

All Articles