[ 
https://issues.apache.org/jira/browse/LOG4J2-2956?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17524822#comment-17524822
 ] 

Ralph Goers commented on LOG4J2-2956:
-------------------------------------

I am now seeing this same error in one of my apps but prior to the exception I 
see this
{code:java}
 java.lang.ExceptionInInitializerError
    at 
org.apache.logging.log4j.core.impl.ThreadContextDataInjector$ForDefaultThreadContextMap.rawContextData(ThreadContextDataInjector.java:171)
    at 
org.apache.logging.log4j.core.filter.ThreadContextMapFilter.currentContextData(ThreadContextMapFilter.java:120)
    at 
org.apache.logging.log4j.core.filter.ThreadContextMapFilter.filter(ThreadContextMapFilter.java:114)
    at 
org.apache.logging.log4j.core.filter.ThreadContextMapFilter.filter(ThreadContextMapFilter.java:89)
    at 
org.apache.logging.log4j.core.filter.CompositeFilter.filter(CompositeFilter.java:543)
    at 
org.apache.logging.log4j.core.Logger$PrivateConfig.filter(Logger.java:609)
    at org.apache.logging.log4j.core.Logger.isEnabled(Logger.java:258)
    at 
org.apache.logging.log4j.spi.AbstractLogger.isEnabled(AbstractLogger.java:1513)
    at 
org.apache.commons.logging.LogAdapter$Log4jLog.isDebugEnabled(LogAdapter.java:190)
    at 
org.springframework.core.env.SystemEnvironmentPropertySource.getProperty(SystemEnvironmentPropertySource.java:94)
    at 
org.springframework.boot.env.SystemEnvironmentPropertySourceEnvironmentPostProcessor$OriginAwareSystemEnvironmentPropertySource.getProperty(SystemEnvironmentPropertySourceEnvironmentPostProcessor.java:107)
    at 
org.springframework.boot.context.properties.source.SpringConfigurationPropertySource.getConfigurationProperty(SpringConfigurationPropertySource.java:84)
    at 
org.springframework.boot.context.properties.source.SpringIterableConfigurationPropertySource.getConfigurationProperty(SpringIterableConfigurationPropertySource.java:100)
    at 
org.springframework.boot.context.properties.source.ConfigurationPropertySourcesPropertySource.findConfigurationProperty(ConfigurationPropertySourcesPropertySource.java:70)
    at 
org.springframework.boot.context.properties.source.ConfigurationPropertySourcesPropertySource.findConfigurationProperty(ConfigurationPropertySourcesPropertySource.java:58)
    at 
org.springframework.boot.context.properties.source.ConfigurationPropertySourcesPropertySource.containsProperty(ConfigurationPropertySourcesPropertySource.java:42)
    at 
org.springframework.core.env.PropertySourcesPropertyResolver.containsProperty(PropertySourcesPropertyResolver.java:51)
    at 
org.springframework.core.env.AbstractEnvironment.containsProperty(AbstractEnvironment.java:588)
    at 
org.apache.logging.log4j.spring.boot.SpringPropertySource.containsProperty(SpringPropertySource.java:50)
    at 
org.apache.logging.log4j.util.PropertiesUtil$Environment.get(PropertiesUtil.java:493)
    at 
org.apache.logging.log4j.util.PropertiesUtil$Environment.access$200(PropertiesUtil.java:420)
    at 
org.apache.logging.log4j.util.PropertiesUtil.getStringProperty(PropertiesUtil.java:368)
    at 
org.apache.logging.log4j.util.PropertiesUtil.getBooleanProperty(PropertiesUtil.java:141)
    at 
org.apache.logging.log4j.util.PropertiesUtil.getBooleanProperty(PropertiesUtil.java:130)
    at org.apache.logging.log4j.core.jmx.Server.isJmxDisabled(Server.java:131)
    at 
org.apache.logging.log4j.core.jmx.Server.reregisterMBeansAfterReconfigure(Server.java:136)
    at 
org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:637)
    at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:302)
    at 
org.apache.logging.log4j.spring.boot.Log4j2CloudConfigLoggingSystem.loadConfiguration(Log4j2CloudConfigLoggingSystem.java:124)
    at 
org.springframework.boot.logging.log4j2.Log4J2LoggingSystem.loadConfiguration(Log4J2LoggingSystem.java:181)
    at 
org.springframework.boot.logging.AbstractLoggingSystem.initializeWithSpecificConfig(AbstractLoggingSystem.java:66)
    at 
org.springframework.boot.logging.AbstractLoggingSystem.initialize(AbstractLoggingSystem.java:57)
    at 
org.springframework.boot.logging.log4j2.Log4J2LoggingSystem.initialize(Log4J2LoggingSystem.java:163)
    at 
org.apache.logging.log4j.spring.boot.Log4j2CloudConfigLoggingSystem.initialize(Log4j2CloudConfigLoggingSystem.java:81)
    at 
org.springframework.boot.context.logging.LoggingApplicationListener.initializeSystem(LoggingApplicationListener.java:316)
    at 
org.springframework.boot.context.logging.LoggingApplicationListener.initialize(LoggingApplicationListener.java:282)
    at 
org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEnvironmentPreparedEvent(LoggingApplicationListener.java:240)
    at 
org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:216)
    at 
org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:176)
    at 
org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:169)
    at 
org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:143)
    at 
org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:131)
    at 
org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:82)
    at 
org.springframework.boot.SpringApplicationRunListeners.lambda$environmentPrepared$2(SpringApplicationRunListeners.java:63)
    at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
    at 
org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:117)
    at 
org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:111)
    at 
org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:62)
    at 
org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:375)
    at 
org.springframework.boot.SpringApplication.run(SpringApplication.java:333)
    at 
org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:143)
    at 
org.springframework.cloud.bootstrap.BootstrapApplicationListener.bootstrapServiceContext(BootstrapApplicationListener.java:197)
    at 
org.springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:114)
    at 
org.springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:77)
    at 
org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:176)
    at 
org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:169)
    at 
org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:143)
    at 
org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:131)
    at 
org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:82)
    at 
org.springframework.boot.SpringApplicationRunListeners.lambda$environmentPrepared$2(SpringApplicationRunListeners.java:63)
    at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
    at 
org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:117)
    at 
org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:111)
    at 
org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:62)
    at 
org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:375)
    at 
org.springframework.boot.SpringApplication.run(SpringApplication.java:333)
    at 
org.springframework.boot.SpringApplication.run(SpringApplication.java:1365)
    at 
org.springframework.boot.SpringApplication.run(SpringApplication.java:1354)
    at com.nextiva.smsgateway.service.Application.main(Application.java:27)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native 
Method)
    at 
java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at 
java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at 
org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49)
    at org.springframework.boot.loader.Launcher.launch(Launcher.java:108)
    at org.springframework.boot.loader.Launcher.launch(Launcher.java:58)
    at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:88)
Caused by: java.lang.NullPointerException
    at 
org.apache.logging.log4j.core.filter.ThreadContextMapFilter.filter(ThreadContextMapFilter.java:114)
    at 
org.apache.logging.log4j.core.filter.ThreadContextMapFilter.filter(ThreadContextMapFilter.java:89)
    at 
org.apache.logging.log4j.core.filter.CompositeFilter.filter(CompositeFilter.java:543)
    at 
org.apache.logging.log4j.core.Logger$PrivateConfig.filter(Logger.java:609)
    at org.apache.logging.log4j.core.Logger.isEnabled(Logger.java:258)
    at 
org.apache.logging.log4j.spi.AbstractLogger.isEnabled(AbstractLogger.java:1513)
    at 
org.apache.commons.logging.LogAdapter$Log4jLog.isDebugEnabled(LogAdapter.java:190)
    at 
org.springframework.core.env.SystemEnvironmentPropertySource.getProperty(SystemEnvironmentPropertySource.java:94)
    at 
org.springframework.boot.env.SystemEnvironmentPropertySourceEnvironmentPostProcessor$OriginAwareSystemEnvironmentPropertySource.getProperty(SystemEnvironmentPropertySourceEnvironmentPostProcessor.java:107)
    at 
org.springframework.core.env.SystemEnvironmentPropertySource.containsProperty(SystemEnvironmentPropertySource.java:83)
    at 
org.springframework.boot.env.SystemEnvironmentPropertySourceEnvironmentPostProcessor$OriginAwareSystemEnvironmentPropertySource.containsProperty(SystemEnvironmentPropertySourceEnvironmentPostProcessor.java:102)
    at 
org.springframework.core.env.PropertySourcesPropertyResolver.containsProperty(PropertySourcesPropertyResolver.java:51)
    at 
org.springframework.core.env.AbstractEnvironment.containsProperty(AbstractEnvironment.java:588)
    at 
org.apache.logging.log4j.spring.boot.SpringPropertySource.containsProperty(SpringPropertySource.java:50)
    at 
org.apache.logging.log4j.util.PropertiesUtil$Environment.get(PropertiesUtil.java:493)
    at 
org.apache.logging.log4j.util.PropertiesUtil$Environment.access$200(PropertiesUtil.java:420)
    at 
org.apache.logging.log4j.util.PropertiesUtil.getStringProperty(PropertiesUtil.java:368)
    at 
org.apache.logging.log4j.core.impl.ContextDataFactory.<clinit>(ContextDataFactory.java:49)
    ... 77 more{code}
It seems that JMX is looking up a property that references Spring and it is 
trying to log something right after the configuration has been stored. It then 
tries to initialize ContextDataFactory but once again needs to look up a 
property and once again that tries to lookup a property. So the end result is 
that it finally ends up with an uninitialized ContextDataFactory and gets the 
NPE.

> Using log4j-spring-cloud-config-client and DynamicThresholdFilter cause Could 
> not initialize class 
> org.apache.logging.log4j.core.impl.ContextDataFactoryException
> -----------------------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: LOG4J2-2956
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-2956
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: Spring
>    Affects Versions: 2.13.3
>            Reporter: Rafał Figas
>            Priority: Major
>
> Assumptions:
>  # Application is a Spring Boot app.
>  # {{It is configured to use spring-boot-starter-log4j2}}
> {{There is a log4j2.cfg.xml provided through logging.config property and it 
> is working fine. It contains following part:}}
>  
> {noformat}
> <DynamicThresholdFilter key="X-Log-Level" onMatch="ACCEPT" 
> onMismatch="NEUTRAL">   
>  <DefaultThreshold>INFO</DefaultThreshold>
>  <KeyValuePair key="DEBUG" value="DEBUG" />
>  <KeyValuePair key="TRACE" value="TRACE" />
> </DynamicThresholdFilter>{noformat}
> {{However when dependency log4j-spring-cloud-config-client is added 
> application does not start with following exception:}}
> {noformat}
> Exception in thread "main" java.lang.NoClassDefFoundError: Could not 
> initialize class 
> org.apache.logging.log4j.core.impl.ContextDataFactoryException in thread 
> "main" java.lang.NoClassDefFoundError: Could not initialize class 
> org.apache.logging.log4j.core.impl.ContextDataFactory 
> at 
> org.apache.logging.log4j.core.impl.ThreadContextDataInjector$ForDefaultThreadContextMap.rawContextData(ThreadContextDataInjector.java:137)
>  
> at 
> org.apache.logging.log4j.core.filter.DynamicThresholdFilter.currentContextData(DynamicThresholdFilter.java:162)
>  
> at 
> org.apache.logging.log4j.core.filter.DynamicThresholdFilter.filter(DynamicThresholdFilter.java:152)
>  at 
> org.apache.logging.log4j.core.Logger$PrivateConfig.filter(Logger.java:609) 
> at org.apache.logging.log4j.core.Logger.isEnabled(Logger.java:258) at 
> org.apache.logging.log4j.spi.AbstractLogger.isEnabled(AbstractLogger.java:1513)
>  
> at 
> org.apache.commons.logging.LogAdapter$Log4jLog.isErrorEnabled(LogAdapter.java:175)
>  at 
> org.springframework.boot.SpringApplication.reportFailure(SpringApplication.java:836)
>  
> at 
> org.springframework.boot.SpringApplication.handleRunFailure(SpringApplication.java:812)
>  at 
> org.springframework.boot.SpringApplication.run(SpringApplication.java:325) 
> at 
> org.springframework.boot.SpringApplication.run(SpringApplication.java:1237) 
> at 
> org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) 
> at 
> pl.frati.moray.configserver.ConfigServerApplication.main(ConfigServerApplication.java:12)
> {noformat}
> First of all I have no idea what is missing. Without mentioned dependency 
> application startup is correct. Also, removing DynamicThresholdFilter solves 
> the problem as well.
> Second of all it seems that exception message is somewhat broken, because it 
> does not say anything about what class is missing. I've tried to debug this, 
> but class ContextDataFactory is pretty hard to debug. Fix in exception 
> message should ease the hunt.
>  



--
This message was sent by Atlassian Jira
(v8.20.7#820007)

Reply via email to