Direct buffers in java 9? Reflections on java classes fails on java 9.
See original GitHub issueI can’t find anything in other issues, so I want to ask if there are any plans for implementing direct buffers in netty for java 9? Currently it fails to get address field of direct byte buffer field due to java 9 modules that disallows for reflection usage on java classes (why they done that…). https://github.com/netty/netty/blob/4f6ef695822253715dc75cd7355f3325505cae67/common/src/main/java/io/netty/util/internal/PlatformDependent0.java#L72
It is still possible to workaround this, but this isn’t pretty solution, as Unsafe can be used to access reflections, with at least 3 possible ways:
- using unsafe to get address field.
- get
setAccessible0
method and make it public (change modifiers field in Method class) using unsafe, then use it for any field/method used to reflect java classes. - get needed method/field and make it public using unsafe.
EDIT: seems that this can be avoided by adding:
--add-opens=java.base/java.nio=ALL-UNNAMED
startup flag.
But what next? if they plan to remove unsafe, they will probably do it in java 10. Also java 9 isn’t stable yet, so this can be changed later too.
Or maybe there is some other way to tell java to disable that extra module checks? Or other workaround? Like some startup flag, etc… But I didn’t find anything.
Java version: build 9-ea+153-jigsaw-nightly-h6000-20170123
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (3 by maintainers)
@Scottmitch ok, with some help I found that
--add-opens=java.base/java.nio=ALL-UNNAMED
flag will work here, but so far I didn’t find any runtime way. But this is good enough for now.This can be closed now as we fixed it.