java.lang.NoClassDefFoundError: Could not initialize class io.netty.util.concurrent.DefaultPromise
Exception in thread "main" java.lang.NoClassDefFoundError: Could not initialize class io.netty.util.concurrent.DefaultPromise
at io.netty.util.concurrent.MultithreadEventExecutorGroup.<init>(MultithreadEventExecutorGroup.java:35)
at io.netty.channel.MultithreadEventLoopGroup.<init>(MultithreadEventLoopGroup.java:49)
at io.netty.channel.nio.NioEventLoopGroup.<init>(NioEventLoopGroup.java:61)
at io.netty.channel.nio.NioEventLoopGroup.<init>(NioEventLoopGroup.java:52)
at io.netty.channel.nio.NioEventLoopGroup.<init>(NioEventLoopGroup.java:44)
at io.netty.channel.nio.NioEventLoopGroup.<init>(NioEventLoopGroup.java:36)
at Main.main(Main.java:9)
With:
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="debug" strict="true" name="XMLConfigTest">
<Appenders>
<Appender type="Console" name="STDOUT"/>
<GELF name="GrayLog"/>
</Appenders>
<Loggers>
<Root level="trace">
<AppenderRef ref="STDOUT"/>
</Root>
</Loggers>
</Configuration>
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>graylog2-issue</groupId>
<artifactId>graylog2-issue</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<log4j.version>2.6.2</log4j.version>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${log4j.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>${log4j.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.graylog2.log4j2</groupId>
<artifactId>log4j2-gelf</artifactId>
<version>1.3.0</version>
</dependency>
</dependencies>
</project>
import io.netty.channel.nio.NioEventLoopGroup;
import java.net.MalformedURLException;
import java.net.UnknownHostException;
public class Main {
public static void main(String... args) throws UnknownHostException, MalformedURLException {
NioEventLoopGroup group = new NioEventLoopGroup();
}
}
I tried to analyze the issue, and as I understand it, it is an chicken&egg problem: at init time Netty is trying to log into gelf which uses not yet initialized Netty \o/
@juherr Thanks for reporting this.
The following Java class is working (you also have to change the dependency scope of org.apache.logging.log4j:log4j-core accordingly):
import org.apache.logging.log4j.LogManager;
public class Main {
public static void main(String... args) {
LogManager.getLogger(Main.class).info("Test");
}
}
While the original error message is interesting, I don't see any bug with log4j2-gelf but rather a classpath issue with the project.
The problem is on NioEventLoopGroup group = new NioEventLoopGroup(); and in my real-life usage, I'm not the one who calls it.
Are you able to create a NioEventLoopGroup?
Without the log4j-slf4j-impl dependency, it is working like a charm too because Netty won't use any logger (it doesn't support log4j2 for the moment).
But when you introduce a logger implementation it knows (here, slf4j), then it will fail.
@juherr I see. It looks like Maven is pulling in the shaded version of log4j2-gelf instead of the normal version.
Try using this dependency instead:
<dependency>
<groupId>org.graylog2.log4j2</groupId>
<artifactId>log4j2-gelf</artifactId>
<version>1.3.0</version>
<classifier>jar</classifier>
</dependency>
Awesome! It is working like a charm! Thanks a lot 👍
In fact, it is not working :(
Without <classifier>jar</classifier>
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ graylog2-issue ---
Downloading: https://jcenter.bintray.com/org/apache/maven/wagon/wagon-provider-api/1.0-alpha-6/wagon-provider-api-1.0-alpha-6.jar
Downloaded: https://jcenter.bintray.com/org/apache/maven/wagon/wagon-provider-api/1.0-alpha-6/wagon-provider-api-1.0-alpha-6.jar (0 B at 0.0 KB/sec)
[INFO] graylog2-issue:graylog2-issue:jar:1.0-SNAPSHOT
[INFO] +- org.apache.logging.log4j:log4j-core:jar:2.6.2:runtime
[INFO] | \- org.apache.logging.log4j:log4j-api:jar:2.6.2:runtime
[INFO] +- org.apache.logging.log4j:log4j-slf4j-impl:jar:2.6.2:runtime
[INFO] | \- org.slf4j:slf4j-api:jar:1.7.21:compile
[INFO] \- org.graylog2.log4j2:log4j2-gelf:jar:1.3.0:compile
[INFO] \- org.graylog2:gelfclient:jar:1.4.0:compile
[INFO] +- io.netty:netty-all:jar:4.0.29.Final:compile
[INFO] \- com.fasterxml.jackson.core:jackson-core:jar:2.5.4:compile
With <classifier>jar</classifier>
[ERROR] Failed to execute goal on project graylog2-issue: Could not resolve dependencies for project graylog2-issue:graylog2-issue:jar:1.0-SNAPSHOT: Failure to find org.graylog2.log4j2:log4j2-gelf:jar:jar:1.3.0 in https://jcenter.bintray.com was cached in the local repository, resolution will not be reattempted until the update interval of jcenter has elapsed or updates are forced -> [Help 1]
It is not a big surprise because log4j2-gelf-1.3.0-jar.jar doesn't exist. I'm just surprised that Maven doesn't complain.
In fact, I'm able to generate the issue without log4j2-gelf: https://github.com/netty/netty/issues/5806
@joschi After all, it looks something should be done in Graylog. Check comment from @Scottmitch: https://github.com/netty/netty/issues/5806#issuecomment-249382910
Well, the shaded artifact resolves the issue. Maybe the documentation should advise using the shaded artifact if the project has already netty in the classpath.