question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Direct buffers in java 9? Reflections on java classes fails on java 9.

See original GitHub issue

I 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:closed
  • Created 7 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
GotoFinalcommented, Jan 25, 2017

@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.

0reactions
normanmaurercommented, Feb 24, 2017

This can be closed now as we fixed it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Fix java.lang.OufOfMemoryError: Direct Buffer Memory
The first case, is pretty straightforward, as your application will fail to start in the first attempt itself, and will not work until...
Read more >
cannot access a member of class java.nio.DirectByteBuffer (in ...
It runs fine in Java 8 as well. Now with Java9, I get problems with nio.DirectByteBuffer, and I tried to solve it this...
Read more >
JDK 9 Release Notes - Oracle
All JDK internal classes are now encapsulated at compile-time. Using javac to compile source code with references to JDK internal classes will now...
Read more >
Java 9 Status tracking - Apache Software Foundation
ThreadLocal leak detection is now hitting Java 9 module issues. Catch the error and provide a useful error message if this happens. Back-ports...
Read more >
Semeru Runtimes migration guide - IBM
The ORB relies on CORBA and RMI-IIOP, which were deprecated by Oracle in Java SE 9 and removed in Java SE 11. Support...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found