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

Java 21 error with LMAX #1962

Closed
jkvargas opened this issue Nov 10, 2023 · 5 comments
Closed

Java 21 error with LMAX #1962

jkvargas opened this issue Nov 10, 2023 · 5 comments
Labels
async Affects asynchronous loggers or appenders bug Incorrect, unexpected, or unintended behavior of existing code runtime Specific to the runtime environment

Comments

@jkvargas
Copy link

Description

While using amazon correto 21 and running the following line:
final static Logger logger = LogManager.getLogger();

I guess it is related to LMAX...

Configuration

Version: 2.21

Operating system: Linux

JDK: correto 21

Logs

Exception in thread "main" java.lang.NoClassDefFoundError: sun/misc/Unsafe
    at com.lmax.disruptor.util.Util$1.run(Util.java:103)
    at com.lmax.disruptor.util.Util$1.run(Util.java:100)
    at java.base/java.security.AccessController.doPrivileged(Unknown Source)
    at com.lmax.disruptor.util.Util.<clinit>(Util.java:109)
    at com.lmax.disruptor.RingBufferFields.<clinit>(RingBuffer.java:34)
    at com.lmax.disruptor.dsl.Disruptor.<init>(Disruptor.java:137)
    at org.apache.logging.log4j.core.async.AsyncLoggerConfigDisruptor.start(AsyncLoggerConfigDisruptor.java:220)
    at org.apache.logging.log4j.core.config.AbstractConfiguration.start(AbstractConfiguration.java:312)
    at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:621)
    at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:694)
    at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:711)
    at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:253)
    at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:155)
    at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:47)
    at org.apache.logging.log4j.LogManager.getContext(LogManager.java:196)
    at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:599)
    at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:585)
    at Main.<clinit>(Main.java:25)
Caused by: java.lang.ClassNotFoundException: sun.misc.Unsafe
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(Unknown Source)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(Unknown Source)
    at java.base/java.lang.ClassLoader.loadClass(Unknown Source)

@jvz
Copy link
Member

jvz commented Nov 10, 2023

Might be related to #1829.

@jvz jvz added bug Incorrect, unexpected, or unintended behavior of existing code runtime Specific to the runtime environment async Affects asynchronous loggers or appenders labels Nov 10, 2023
@jvz
Copy link
Member

jvz commented Nov 10, 2023

This might show up elsewhere in Log4j, actually, so it's not entirely solved by an LMAX upgrade here. This issue can be expanded to any other sun.misc.Unsafe usage (I'm pretty sure the mmap appender uses it amongst others).

Update: only other place is in MemoryMappedFileManager. The LMAX issue is hopefully solved by an update in LMAX.

@jkvargas
Copy link
Author

jkvargas commented Nov 13, 2023

hi @jvz ,
I am trying to reproduce the issue with the smallest app possible running on ubuntu linux with java 21 and version 2.+

app is quite simple:

package reproduce;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class App {
    private static Logger logger = LogManager.getLogger();

    public static void main(String[] args) {
        logger.info("test");
    }
}

and this is the config file.

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
    <Appenders>
        <!-- Define a Console appender -->
        <Console name="Console" target="SYSTEM_OUT">
            <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
        </Console>
    </Appenders>

    <!-- Use the AsyncAppender as the root logger -->
    <Loggers>
        <AsyncRoot level="WARN">
            <AppenderRef ref="Console"/>
        </AsyncRoot>
        <AsyncLogger level="info" includeLocation="true">
            <AppenderRef ref="Console"/>
        </AsyncLogger>
    </Loggers>
</Configuration>

this throws Caused by: java.lang.ClassNotFoundException: com.lmax.disruptor.EventHandler but does not seem to be the same problem.
What exactly is what triggers the problem?

@jvz
Copy link
Member

jvz commented Nov 14, 2023

The trigger for this particular issue is that somewhere in LMAX, it uses sun.misc.Unsafe without catching java.lang.NoClassDefFoundError at the call site where they load it. You need to add that dependency to the class path to reproduce this.

@ppkarwasz
Copy link
Contributor

sun.misc.Unsafe was removed from LMAX Disruptor two years ago: LMAX-Exchange/disruptor@63f9abc

Version 4.0.0 should run without problems (once we add support for 4.x).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
async Affects asynchronous loggers or appenders bug Incorrect, unexpected, or unintended behavior of existing code runtime Specific to the runtime environment
Projects
None yet
Development

No branches or pull requests

3 participants