
Why not using UnsafeAccessor Library to get sun.misc.Unsafe instance with better compatibility and convenience.
lvyitian opened this issue · 1 comments
Library: https://bintray.com/karlatemp/unsafe-accessor/unsafe-accessor/
Github(outdated): https://github.com/Karlatemp/UnsafeAccessor
How does it work: https://karlatemp.github.io/blog-me/reflect/0.index.html
It uses a much more ingenious method to get Unsafe instance without trigger “WARNING: An illegal reflective access operation has occurred”.
I think it can fix the compatibility issue with java 9+ perfectly.
Just add jcenter to maven repo list and add content below to build.gradle:
implementation 'io.github.karlatemp:unsafe-accessor:1.2.0'
Use io.github.karlatemp.unsafeaccessor.Root.getUnsafe()
to get wrapped Unsafe and then call wrappedUnsafe.getUnsafe()
to get sun.misc.Unsafe.
It also provides some useful methods like void io.github.karlatemp.unsafeaccessor.Root.setAccessible(AccessibleObject object, boolean isAccessible)
and MethodHandles.Lookup io.github.karlatemp.unsafeaccessor.Root.getTrusted()
.