Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java 11 disallows sun.misc.unsafe access from a module #1317

Closed
cayhorstmann opened this issue May 10, 2018 · 4 comments
Closed

Java 11 disallows sun.misc.unsafe access from a module #1317

cayhorstmann opened this issue May 10, 2018 · 4 comments

Comments

@cayhorstmann
Copy link

Putting the gson JAR on the module path makes the call

 unsafeClass = Class.forName("sun.misc.Unsafe");

fail in Java 11. You might as well check that at the place where you check for version numbers, and switch to reflective access. Users who do put the JAR on the module path should know to open any packages whose classes are being accessed by reflection.

@inder123
Copy link
Collaborator

Thanks. Can you explain what you mean by "switch to reflective access"? Isn't Class.forName() already reflective access?

@cayhorstmann
Copy link
Author

Sorry for being obtuse. You have two strategies for looking at the fields of an object: PreJava9ReflectionAccessor and UnsafeReflectionAccessor. The UnsafeReflectionAccessor will fail in Java 11 if the Gson JAR file is on the module path. This is not fatal because each time it fails, you will fall back to PreJava9ReflectionAccessor. But you might as well do the test once in ReflectionAccessor and be done with it.

@AlanBateman
Copy link

If gson is compiled or deployed as an explicit and it is using sun.misc.Unsafe then it needs requires jdk.unsupported in its module declaration. If gon is deployed as an automatic module then it won't read the jdk.unsupported if it's not resolved. The jdk.unsupported module will be resolved if some module requires jdk.unsupported or you run with --add-modules jdk.unsupported.

@Marcono1234
Copy link
Collaborator

Might have been fixed by #1993 which added requires static jdk.unsupported;.

@eamonnmcmanus eamonnmcmanus closed this as not planned Won't fix, can't repro, duplicate, stale Jul 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants