java - netty epoll native 在 linux (debian) 中抛出 java.lang.IllegalArgumentException

标签 java linux netty

启动应用程序时,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/

相关文章:

linux - 无线wlan0管理

java - 用 Java 绘制图像,在上网本上慢得要命

java - Spring,基于注解,覆盖组件

java - 未使用 tomcat jndi ldap userSearchAsUser

java - 无法启动 OSGi 包,缺少 com.ibm.uvm.tools

linux - 能不能git clone redhat内核源码看看他们做了什么改动?

netty - Netty 和 JGroups 之间的主要区别是什么?

java - Netty SSL header

java - 这是 Netty 从封闭 channel 读取数据的示例吗?

Java vanClass 给出找不到符号错误