简体   繁体   中英

netty epoll native throw java.lang.IllegalArgumentException in linux(debian)

When start application, the following exception is thrown from 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)

The reason is caused by another library which contains the android-2.3.3.jar. Netty EPOLL native try to detect the system by checking the functions & class. In the PlatformDependent::isAndroid0(), because of the android jar, it will believe itself is running in android.

 private static boolean isAndroid0() {
    boolean android;
    try {
        Class.forName("android.app.Application", false, getSystemClassLoader());
        android = true;
 ...

So the function hasUnsafe0() will wrongly believe there is no sun.misc.Unsafe.

private static boolean hasUnsafe0() {
    if(isAndroid()) {
        logger.debug("sun.misc.Unsafe: unavailable (Android)");
        return false;

Because of this, the exception is thrown when it is calling the native memory allocation. Its parameter is negative value!!!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM