启动应用程序时,netty抛出以下异常
Caused by: java.lang.IllegalArgumentException
at sun.misc.Unsafe.allocateMemory(Native Method)
at io.netty.util.internal.PlatformDependent0.allocateMemory(PlatformDependent0.java:627)
at io.netty.util.internal.PlatformDependent.allocateMemory(PlatformDependent.java:262)
at io.netty.channel.epoll.IovArray.<init>(IovArray.java:64)
at io.netty.channel.epoll.EpollEventLoop.<init>(EpollEventLoop.java:62)
at io.netty.channel.epoll.EpollEventLoopGroup.newChild(EpollEventLoopGroup.java:130)
at io.netty.channel.epoll.EpollEventLoopGroup.newChild(EpollEventLoopGroup.java:35)
at io.netty.util.concurrent.MultithreadEventExecutorGroup.<init>(MultithreadEventExecutorGroup.java:84)
最佳答案
原因是另一个包含android-2.3.3.jar的库引起的。 Netty EPOLL native 尝试通过检查函数和类来检测系统。在 PlatformDependent::isAndroid0() 中,由于 android jar,它会认为自己在 android 中运行。
private static boolean isAndroid0() {
boolean android;
try {
Class.forName("android.app.Application", false, getSystemClassLoader());
android = true;
...
所以函数 hasUnsafe0() 会错误地认为没有 sun.misc.Unsafe。
private static boolean hasUnsafe0() {
if(isAndroid()) {
logger.debug("sun.misc.Unsafe: unavailable (Android)");
return false;
因此,在调用 native 内存分配时会抛出异常。它的参数是负值!!!
关于java - netty epoll native 在 linux (debian) 中抛出 java.lang.IllegalArgumentException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39709232/