Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

org.slf4j.LoggerFactory.getLogger fails with java.lang.NoClassDefFoundError: org/slf4j/spi/LoggingEventAware after upgrading to 2.6.0 #397

Closed
tyilo opened this issue Mar 9, 2023 · 3 comments
Assignees
Labels

Comments

@tyilo
Copy link

tyilo commented Mar 9, 2023

Describe the bug
After upgrading from tinylog 2.5.0 to 2.6.0 calling org.slf4j.LoggerFactory.getLogger("test") causes the following exception:

Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/spi/LoggingEventAware
	at java.lang.ClassLoader.defineClass1(Native Method)
	at java.lang.ClassLoader.defineClass(ClassLoader.java:756)
	at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
	at java.net.URLClassLoader.defineClass(URLClassLoader.java:473)
	at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:363)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:362)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
	at org.tinylog.slf4j.TinylogLoggerFactory.getLogger(TinylogLoggerFactory.java:37)
	at org.tinylog.slf4j.TinylogLoggerFactory.getLogger(TinylogLoggerFactory.java:24)
	at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:363)
	at org.example.Main.main(Main.java:8)
Caused by: java.lang.ClassNotFoundException: org.slf4j.spi.LoggingEventAware
	at java.net.URLClassLoader.findClass(URLClassLoader.java:387)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
	... 16 more

To Reproduce
Steps to reproduce the behavior:

  1. Create a new maven project with the following files:
    pom.xml:
<?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>org.example</groupId>
    <artifactId>tinylog-test</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

        <tinylog.version>2.5.0</tinylog.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.tinylog</groupId>
            <artifactId>tinylog-api</artifactId>
            <version>${tinylog.version}</version>
        </dependency>
        <dependency>
            <groupId>org.tinylog</groupId>
            <artifactId>tinylog-impl</artifactId>
            <version>${tinylog.version}</version>
        </dependency>
        <dependency>
            <groupId>org.tinylog</groupId>
            <artifactId>slf4j-tinylog</artifactId>
            <version>${tinylog.version}</version>
            <scope>runtime</scope>
        </dependency>

        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.7.36</version>
        </dependency>
    </dependencies>

</project>

src/main/java/org/example/Main.java:

package org.example;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Main {
  public static void main(String[] args) {
    Logger logger = LoggerFactory.getLogger("test");
    logger.info("Hello world!");
  }
}
  1. Run it and see that it successfully logs "Hello world!".
  2. Change tinylog.version from 2.5.0 to 2.6.0 in pom.xml.
  3. Run it again and see that we now get the NoClassDefFoundError.

Environment
tinylog version: 2.6.0
Java version: 1.8.0_362

@tyilo tyilo added the bug label Mar 9, 2023
@pmwmedia pmwmedia self-assigned this Mar 9, 2023
pmwmedia added a commit that referenced this issue Mar 9, 2023
LoggerFactory failed to load org.slf4j.spi.LoggingEventAware.

Fixes #397
@pmwmedia
Copy link
Member

pmwmedia commented Mar 9, 2023

Thank you for the well documented bug report! It really made it pleasant to reproduce and fix the bug.

@pmwmedia pmwmedia closed this as completed Mar 9, 2023
@pmwmedia
Copy link
Member

pmwmedia commented Mar 9, 2023

I have just released tinylog 2.6.1. Please let me know if the fix works for you!

@tyilo
Copy link
Author

tyilo commented Mar 10, 2023

It works :) Thanks for the quick fix.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 18, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

No branches or pull requests

2 participants