bfreitastgtg opened a new issue, #3240:
URL: https://github.com/apache/logging-log4j2/issues/3240

   ## Description
   
   Trying to use a logger in a class annotated with `@Plugin` from 
`org.apache.logging.log4j.core.config.plugins` throws an exception. The same 
problem does not happen on versions 2.23.1, 2.24.0 and 2.24.1.
   
   ## Configuration
   
   **Version:** 2.24.2
   
   **Operating system:** linux
   
   **JDK:** Amazon Correto, 21
   
   ## Logs
   
   ```
   2024-11-26T08:33:59.000998374Z main ERROR Unable to create Lookup for 
myplugin java.lang.IllegalArgumentException: 
java.lang.ExceptionInInitializerError
        at 
org.apache.logging.log4j.core.util.ReflectionUtil.instantiate(ReflectionUtil.java:192)
        at 
org.apache.logging.log4j.core.lookup.Interpolator.<init>(Interpolator.java:90)
        at 
org.apache.logging.log4j.core.lookup.Interpolator.<init>(Interpolator.java:109)
        at 
org.apache.logging.log4j.core.config.AbstractConfiguration.<init>(AbstractConfiguration.java:137)
        at 
org.apache.logging.log4j.core.config.NullConfiguration.<init>(NullConfiguration.java:32)
        at 
org.apache.logging.log4j.core.LoggerContext.<clinit>(LoggerContext.java:77)
        at 
org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.createContext(ClassLoaderContextSelector.java:265)
        at 
org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.locateContext(ClassLoaderContextSelector.java:224)
        at 
org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.getContext(ClassLoaderContextSelector.java:142)
        at 
org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.getContext(ClassLoaderContextSelector.java:125)
        at 
org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.getContext(ClassLoaderContextSelector.java:119)
        at 
org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:148)
        at 
org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:46)
        at org.apache.logging.log4j.LogManager.getContext(LogManager.java:138)
        at 
org.apache.logging.log4j.spi.AbstractLoggerAdapter.getContext(AbstractLoggerAdapter.java:136)
        at 
org.apache.logging.slf4j.Log4jLoggerFactory.getContext(Log4jLoggerFactory.java:58)
        at 
org.apache.logging.log4j.spi.AbstractLoggerAdapter.getLogger(AbstractLoggerAdapter.java:46)
        at 
org.apache.logging.slf4j.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:32)
        at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:432)
        at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:457)
           (...)
   Caused by: java.lang.ExceptionInInitializerError
        at java.base/jdk.internal.misc.Unsafe.ensureClassInitialized0(Native 
Method)
        at 
java.base/jdk.internal.misc.Unsafe.ensureClassInitialized(Unsafe.java:1160)
        at 
java.base/jdk.internal.reflect.MethodHandleAccessorFactory.ensureClassInitialized(MethodHandleAccessorFactory.java:300)
        at 
java.base/jdk.internal.reflect.MethodHandleAccessorFactory.newConstructorAccessor(MethodHandleAccessorFactory.java:103)
        at 
java.base/jdk.internal.reflect.ReflectionFactory.newConstructorAccessor(ReflectionFactory.java:200)
        at 
java.base/java.lang.reflect.Constructor.acquireConstructorAccessor(Constructor.java:549)
        at 
java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
        at 
java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:486)
        at 
org.apache.logging.log4j.core.util.ReflectionUtil.instantiate(ReflectionUtil.java:188)
        ... 20 more
   Caused by: java.lang.NullPointerException: messageFactory
        at java.base/java.util.Objects.requireNonNull(Objects.java:259)
        at 
org.apache.logging.log4j.core.util.internal.InternalLoggerRegistry.computeIfAbsent(InternalLoggerRegistry.java:135)
        at 
org.apache.logging.log4j.core.LoggerContext.getLogger(LoggerContext.java:530)
        at 
org.apache.logging.log4j.core.LoggerContext.getLogger(LoggerContext.java:503)
        at 
org.apache.logging.log4j.core.LoggerContext.getLogger(LoggerContext.java:65)
        at 
org.apache.logging.slf4j.Log4jLoggerFactory.newLogger(Log4jLoggerFactory.java:49)
        at 
org.apache.logging.slf4j.Log4jLoggerFactory.newLogger(Log4jLoggerFactory.java:32)
        at 
org.apache.logging.log4j.spi.AbstractLoggerAdapter.getLogger(AbstractLoggerAdapter.java:52)
        at 
org.apache.logging.slf4j.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:32)
        at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:432)
        at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:457)
        (...)
        ... 29 more
   ```
   
   ## Reproduction
   The code below used to run fine, then after upgrading to 2.24.2 it started 
throwing on application startup. Getting rid of the `LOGGER` variable "fixes" 
the problem. 
   ```
   import org.apache.logging.log4j.core.LogEvent;
   import org.apache.logging.log4j.core.config.plugins.Plugin;
   import org.apache.logging.log4j.core.lookup.StrLookup;
   import org.slf4j.Logger;
   import org.slf4j.LoggerFactory;
   
   @Plugin(name = "MyPlugin", category = StrLookup.CATEGORY)
   public class MyPlugin implements StrLookup {
     private static final Logger LOGGER = 
LoggerFactory.getLogger(MyPlugin.class);
   
     static {
       LOGGER.info("Log stuff");
     }
   
     @Override
     public String lookup(String key) {
       return "";
     }
   
     @Override
     public String lookup(LogEvent event, String key) {
       return "";
     }
   }
   ```
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to