一个关于用netty的小错误反思
一个关于用netty的小认知
在使用netty时,观看了黑马的netty网课,没想就直接用他的依赖了
依赖如下
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
<version>4.1.39.Final</version>
</dependency>
不过幸运的是,我意识到了老师的没有问题,而我的出了问题,在代码相同性排查后,我就感觉到是可能是java版本的问题
我是使用jdk17而老师的是jdk8
当然这里就水落石出了
报错如下:
java.lang.UnsupportedOperationException: Reflective setAccessible(true) disabled
at io.netty.util.internal.ReflectionUtil.trySetAccessible(ReflectionUtil.java:31)
at io.netty.util.internal.PlatformDependent0$4.run(PlatformDependent0.java:224)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:318)
at io.netty.util.internal.PlatformDependent0.<clinit>(PlatformDependent0.java:218)
at io.netty.util.internal.PlatformDependent.isAndroid(PlatformDependent.java:272)
at io.netty.util.internal.PlatformDependent.<clinit>(PlatformDependent.java:92)
at io.netty.channel.nio.NioEventLoop.newTaskQueue0(NioEventLoop.java:284)
at io.netty.channel.nio.NioEventLoop.newTaskQueue(NioEventLoop.java:155)
at io.netty.channel.nio.NioEventLoop.<init>(NioEventLoop.java:137)
at io.netty.channel.nio.NioEventLoopGroup.newChild(NioEventLoopGroup.java:138)
at io.netty.channel.nio.NioEventLoopGroup.newChild(NioEventLoopGroup.java:37)
at io.netty.util.concurrent.MultithreadEventExecutorGroup.<init>(MultithreadEventExecutorGroup.java:84)
at io.netty.util.concurrent.MultithreadEventExecutorGroup.<init>(MultithreadEventExecutorGroup.java:58)
at io.netty.channel.MultithreadEventLoopGroup.<init>(MultithreadEventLoopGroup.java:52)
at io.netty.channel.nio.NioEventLoopGroup.<init>(NioEventLoopGroup.java:88)
at io.netty.channel.nio.NioEventLoopGroup.<init>(NioEventLoopGroup.java:83)
at io.netty.channel.nio.NioEventLoopGroup.<init>(NioEventLoopGroup.java:64)
at io.netty.channel.nio.NioEventLoopGroup.<init>(NioEventLoopGroup.java:52)
at io.netty.channel.nio.NioEventLoopGroup.<init>(NioEventLoopGroup.java:44)
at netty.helloworld.Server.main(Server.java:22)
23:33:58.458 [main] DEBUG io.netty.util.internal.PlatformDependent0 - java.nio.Bits.unaligned: available, true
23:33:58.459 [main] DEBUG io.netty.util.internal.PlatformDependent0 - jdk.internal.misc.Unsafe.allocateUninitializedArray(int): unavailable
java.lang.IllegalAccessException: class io.netty.util.internal.PlatformDependent0$6 cannot access class jdk.internal.misc.Unsafe (in module java.base) because module java.base does not export jdk.internal.misc to unnamed module @7c0e2abd
at java.base/jdk.internal.reflect.Reflection.newIllegalAccessException(Reflection.java:392)
at java.base/java.lang.reflect.AccessibleObject.checkAccess(AccessibleObject.java:674)
at java.base/java.lang.reflect.Method.invoke(Method.java:560)
at io.netty.util.internal.PlatformDependent0$6.run(PlatformDependent0.java:334)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:318)
at io.netty.util.internal.PlatformDependent0.<clinit>(PlatformDependent0.java:325)
at io.netty.util.internal.PlatformDependent.isAndroid(PlatformDependent.java:272)
at io.netty.util.internal.PlatformDependent.<clinit>(PlatformDependent.java:92)
at io.netty.channel.nio.NioEventLoop.newTaskQueue0(NioEventLoop.java:284)
at io.netty.channel.nio.NioEventLoop.newTaskQueue(NioEventLoop.java:155)
at io.netty.channel.nio.NioEventLoop.<init>(NioEventLoop.java:137)
at io.netty.channel.nio.NioEventLoopGroup.newChild(NioEventLoopGroup.java:138)
at io.netty.channel.nio.NioEventLoopGroup.newChild(NioEventLoopGroup.java:37)
at io.netty.util.concurrent.MultithreadEventExecutorGroup.<init>(MultithreadEventExecutorGroup.java:84)
at io.netty.util.concurrent.MultithreadEventExecutorGroup.<init>(MultithreadEventExecutorGroup.java:58)
at io.netty.channel.MultithreadEventLoopGroup.<init>(MultithreadEventLoopGroup.java:52)
at io.netty.channel.nio.NioEventLoopGroup.<init>(NioEventLoopGroup.java:88)
at io.netty.channel.nio.NioEventLoopGroup.<init>(NioEventLoopGroup.java:83)
at io.netty.channel.nio.NioEventLoopGroup.<init>(NioEventLoopGroup.java:64)
at io.netty.channel.nio.NioEventLoopGroup.<init>(NioEventLoopGroup.java:52)
at io.netty.channel.nio.NioEventLoopGroup.<init>(NioEventLoopGroup.java:44)
at netty.helloworld.Server.main(Server.java:22)
我又突然很想了解这是怎么问题?
总不能之后换了jdk17我就不会了吧(目前状态未意识到版本未一致的问题)
然后查了一下是jdk9后对安全策略之类的进行了更严格的限制之类的
大家通过查找也能查到
然后呢?有了一个新的报错
于是才意识到没准是版本不一致的问题