You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by "Kenny MacLeod (Jira)" <ji...@apache.org> on 2022/02/18 11:14:00 UTC
[jira] [Commented] (LOG4J2-3407) PropertiesConfiguration.parseAppender NPE when logger refers to non-existent appender
[ https://issues.apache.org/jira/browse/LOG4J2-3407?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17494547#comment-17494547 ]
Kenny MacLeod commented on LOG4J2-3407:
---------------------------------------
See attached patch file, apply to the tip of the {{release-2.x}} branch. Includes fix and unit test.
> PropertiesConfiguration.parseAppender NPE when logger refers to non-existent appender
> -------------------------------------------------------------------------------------
>
> Key: LOG4J2-3407
> URL: https://issues.apache.org/jira/browse/LOG4J2-3407
> Project: Log4j 2
> Issue Type: Bug
> Components: Log4j 1.2 bridge
> Affects Versions: 2.17.1
> Reporter: Kenny MacLeod
> Priority: Minor
> Attachments: LOG4J2-3407.patch
>
>
> When parsing a {{log4j.proprties}} file that contains a logger that refers to a non-existent appender, you get a NPE.
> While this is clearly a malformed configuration, Log4j 1.2.x silently ignored this, and the log4j2 bridge should be as tolerant.
> Note that {{PropertiesConfiguration#parseLogger}} is already tolerant of the appender being missing (it does a null check on the result of {{{}parseAppender{}}}), but {{parseAppender}} itself is not tolerant.
> An example config would be:
> {noformat}
> log4j.logger.mylogger=INFO, myappender
> # log4j.appender.myappender=org.apache.log4j.ConsoleAppender
> {noformat}
> The appender has been commented out, to illustrate the bug.
> Stack trace from log4j 2.17.1:
> {noformat}
> Caused by: java.lang.NullPointerException
> at org.apache.log4j.builders.BuilderManager.parseAppender(BuilderManager.java:72)
> at org.apache.log4j.config.PropertiesConfiguration.parseAppender(PropertiesConfiguration.java:428)
> at org.apache.log4j.config.PropertiesConfiguration.parseLogger(PropertiesConfiguration.java:406)
> at org.apache.log4j.config.PropertiesConfiguration.parseLoggers(PropertiesConfiguration.java:351)
> at org.apache.log4j.config.PropertiesConfiguration.doConfigure(PropertiesConfiguration.java:304)
> at org.apache.log4j.config.PropertiesConfiguration.doConfigure(PropertiesConfiguration.java:93)
> at org.apache.log4j.config.Log4j1Configuration.initialize(Log4j1Configuration.java:60)
> at org.apache.logging.log4j.core.config.AbstractConfiguration.start(AbstractConfiguration.java:293)
> at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:626)
> at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:699)
> at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:716)
> at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:270)
> 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.spi.AbstractLoggerAdapter.getContext(AbstractLoggerAdapter.java:137)
> at org.apache.logging.slf4j.Log4jLoggerFactory.getContext(Log4jLoggerFactory.java:55)
> at org.apache.logging.log4j.spi.AbstractLoggerAdapter.getLogger(AbstractLoggerAdapter.java:47)
> at org.apache.logging.slf4j.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:33)
> at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:363)
> at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:388)
> {noformat}
--
This message was sent by Atlassian Jira
(v8.20.1#820001)