Netty- cannot access class jdk.internal.misc.Unsafe

Netty requires access, to a jdk module, so to allow access you need to add a jvm argument when starting your application.

--add-opens java.base/jdk.internal.misc=ALL-UNNAMED

Additionally if you want to disable "java.lang.UnsupportedOperationException: Reflective setAccessible(true) disabled....." warning stacktrace, you can also include:

-Dio.netty.tryReflectionSetAccessible=true

If you are using gradle, you can add these on your build.gradle as follows:

   distributions {
        applicationDefaultJvmArgs = ["--add-opens",
                                     "java.base/jdk.internal.misc=ALL-UNNAMED", "-Dio.netty.tryReflectionSetAccessible=true"]
        mainClassName = 'cl.domain.ServerLauncher'
        archivesBaseName = 'your-service'
        version = 'latest'
        main {
            baseName = 'your-service'
        }
    }

To allow netty to access the class, start java with the following option:

--add-opens java.base/jdk.internal.misc=ALL-UNNAMED

This opens the package jdk.internal.misc in module java.base to the unamed module.

See also the documentation for the java command, and this intro to the Java module system in general.

EDIT: For Netty to use its direct buffer optimizations, you also need to set

-Dio.netty.tryReflectionSetAccessible=true

There are a number of Netty issues on this subject, see e.g. netty/issues/7769


As you said this is just an debug message and can be ignored. It basically tells you that Netty can not make use of "all optimisations" because it can not access a class. If you want you can open up the access level via command line flags when starting your application tho.


When running Netty on Java 11, add these VM options to enable performance optimizations:

--add-opens java.base/jdk.internal.misc=ALL-UNNAMED
-Dio.netty.tryReflectionSetAccessible=true

Then, to know when deep reflection is used, you may add:

--illegal-access=warn