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

Not working in 17 JDK #600

Closed
AcumenDev opened this issue Oct 5, 2021 · 2 comments · Fixed by #660
Closed

Not working in 17 JDK #600

AcumenDev opened this issue Oct 5, 2021 · 2 comments · Fixed by #660

Comments

@AcumenDev
Copy link

AcumenDev commented Oct 5, 2021

Hello, when i use any unpack* metod ( example messageUnpacker.unpackInt()) i recive error

Unable to make private java.nio.DirectByteBuffer(long,int) accessible: module java.base does not "opens java.nio" to unnamed module @5c30a9b0

Probmlem in org.msgpack.core.buffer.DirectBufferAccess and what does he use java.nio.DirectByteBuffer which is closed

Fast decision by add this when you start the JVM : --add-opens java.base/java.nio=ALL-UNNAMED
but it's a crutch(

I use:

'org.msgpack:msgpack-core:0.9.0'

java -version
openjdk version "17" 2021-09-14
OpenJDK Runtime Environment (build 17+35-Ubuntu-120.04)
OpenJDK 64-Bit Server VM (build 17+35-Ubuntu-120.04, mixed mode, sharing)


full stack trace

2021-10-05 16:17:13.717  WARN 36305 --- [ntLoopGroup-3-1] io.netty.channel.DefaultChannelPipeline  : An exceptionCaught() event was fired, and it reached at the tail of the pipeline. It usually means the last handler in the pipeline did not handle the exception.

java.lang.ExceptionInInitializerError: null
	at org.msgpack.core.buffer.MessageBuffer.<init>(MessageBuffer.java:389) ~[msgpack-core-0.9.0.jar:0.9.0]
	at org.msgpack.core.buffer.MessageBuffer.newMessageBuffer(MessageBuffer.java:305) ~[msgpack-core-0.9.0.jar:0.9.0]
	at org.msgpack.core.buffer.MessageBuffer.wrap(MessageBuffer.java:275) ~[msgpack-core-0.9.0.jar:0.9.0]
	at org.msgpack.core.buffer.ByteBufferInput.next(ByteBufferInput.java:57) ~[msgpack-core-0.9.0.jar:0.9.0]
	at org.msgpack.core.MessageUnpacker.getNextBuffer(MessageUnpacker.java:273) ~[msgpack-core-0.9.0.jar:0.9.0]
	at org.msgpack.core.MessageUnpacker.nextBuffer(MessageUnpacker.java:285) ~[msgpack-core-0.9.0.jar:0.9.0]
	at org.msgpack.core.MessageUnpacker.readByte(MessageUnpacker.java:413) ~[msgpack-core-0.9.0.jar:0.9.0]
	at org.msgpack.core.MessageUnpacker.unpackInt(MessageUnpacker.java:939) ~[msgpack-core-0.9.0.jar:0.9.0]
	at com.acumendev.gribcontrol.protocol.msgpack.netty.MsgPackDecoder.findStartPacket(MsgPackDecoder.java:69) ~[main/:na]
	at com.acumendev.gribcontrol.protocol.msgpack.netty.MsgPackDecoder.decode(MsgPackDecoder.java:38) ~[main/:na]
	at io.netty.handler.codec.ByteToMessageDecoder.decodeRemovalReentryProtection(ByteToMessageDecoder.java:507) ~[netty-all-4.1.68.Final.jar:4.1.68.Final]
	at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:446) ~[netty-all-4.1.68.Final.jar:4.1.68.Final]
	at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:276) ~[netty-all-4.1.68.Final.jar:4.1.68.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379) ~[netty-all-4.1.68.Final.jar:4.1.68.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365) ~[netty-all-4.1.68.Final.jar:4.1.68.Final]
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357) ~[netty-all-4.1.68.Final.jar:4.1.68.Final]
	at io.netty.handler.ssl.SslHandler.unwrap(SslHandler.java:1372) ~[netty-all-4.1.68.Final.jar:4.1.68.Final]
	at io.netty.handler.ssl.SslHandler.decodeJdkCompatible(SslHandler.java:1235) ~[netty-all-4.1.68.Final.jar:4.1.68.Final]
	at io.netty.handler.ssl.SslHandler.decode(SslHandler.java:1284) ~[netty-all-4.1.68.Final.jar:4.1.68.Final]
	at io.netty.handler.codec.ByteToMessageDecoder.decodeRemovalReentryProtection(ByteToMessageDecoder.java:507) ~[netty-all-4.1.68.Final.jar:4.1.68.Final]
	at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:446) ~[netty-all-4.1.68.Final.jar:4.1.68.Final]
	at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:276) ~[netty-all-4.1.68.Final.jar:4.1.68.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379) ~[netty-all-4.1.68.Final.jar:4.1.68.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365) ~[netty-all-4.1.68.Final.jar:4.1.68.Final]
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357) ~[netty-all-4.1.68.Final.jar:4.1.68.Final]
	at io.netty.handler.logging.LoggingHandler.channelRead(LoggingHandler.java:280) ~[netty-all-4.1.68.Final.jar:4.1.68.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379) ~[netty-all-4.1.68.Final.jar:4.1.68.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365) ~[netty-all-4.1.68.Final.jar:4.1.68.Final]
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357) ~[netty-all-4.1.68.Final.jar:4.1.68.Final]
	at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410) ~[netty-all-4.1.68.Final.jar:4.1.68.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379) ~[netty-all-4.1.68.Final.jar:4.1.68.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365) ~[netty-all-4.1.68.Final.jar:4.1.68.Final]
	at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919) ~[netty-all-4.1.68.Final.jar:4.1.68.Final]
	at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:166) ~[netty-all-4.1.68.Final.jar:4.1.68.Final]
	at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:719) ~[netty-all-4.1.68.Final.jar:4.1.68.Final]
	at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:655) ~[netty-all-4.1.68.Final.jar:4.1.68.Final]
	at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:581) ~[netty-all-4.1.68.Final.jar:4.1.68.Final]
	at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:493) ~[netty-all-4.1.68.Final.jar:4.1.68.Final]
	at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:986) ~[netty-all-4.1.68.Final.jar:4.1.68.Final]
	at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) ~[netty-all-4.1.68.Final.jar:4.1.68.Final]
	at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) ~[netty-all-4.1.68.Final.jar:4.1.68.Final]
	at java.base/java.lang.Thread.run(Thread.java:833) ~[na:na]
Caused by: java.lang.RuntimeException: java.lang.reflect.InaccessibleObjectException: Unable to make private java.nio.DirectByteBuffer(long,int) accessible: module java.base does not "opens java.nio" to unnamed module @5c30a9b0
	at org.msgpack.core.buffer.DirectBufferAccess.<clinit>(DirectBufferAccess.java:111) ~[msgpack-core-0.9.0.jar:0.9.0]
	... 42 common frames omitted
Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make private java.nio.DirectByteBuffer(long,int) accessible: module java.base does not "opens java.nio" to unnamed module @5c30a9b0
	at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:354) ~[na:na]
	at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297) ~[na:na]
	at java.base/java.lang.reflect.Constructor.checkCanSetAccessible(Constructor.java:188) ~[na:na]
	at java.base/java.lang.reflect.Constructor.setAccessible(Constructor.java:181) ~[na:na]
	at org.msgpack.core.buffer.DirectBufferAccess.<clinit>(DirectBufferAccess.java:98) ~[msgpack-core-0.9.0.jar:0.9.0]
	... 42 common frames omitted

`

@xerial
Copy link
Member

xerial commented Jun 28, 2022

The cause is that creating a new DirectBuffer requires a different implementation for JDK17:

Caused by: java.lang.RuntimeException: java.lang.reflect.InaccessibleObjectException: Unable to make private java.nio.DirectByteBuffer(long,int) accessible: module java.base does not "opens java.nio" to unnamed module @1c3d5e76
	at org.msgpack.core.buffer.DirectBufferAccess.<clinit>(DirectBufferAccess.java:111)
	... 10 more

xerial added a commit that referenced this issue Jun 28, 2022
@xerial xerial mentioned this issue Jun 28, 2022
xerial added a commit that referenced this issue Jun 28, 2022
* Reproduce #600 (JDK17 error)
* Add workaround for Java17
* Add a helpful error message
* Add note on JDK17
@xerial
Copy link
Member

xerial commented Jun 28, 2022

To use DirectByteBuffer in JDK17, two JVM options must be set:

--add-opens=java.base/java.nio=ALL-UNNAMED
--add-opens=java.base/sun.nio.ch=ALL-UNNAMED

If DirectByteBuffer is not used, msgpack-java 0.9.3 will work even if these two options are not set.

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

Successfully merging a pull request may close this issue.

2 participants