Details
-
Bug
-
Status: Resolved
-
Minor
-
Resolution: Fixed
-
2.17.1
-
None
Description
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:
log4j.logger.mylogger=INFO, myappender # log4j.appender.myappender=org.apache.log4j.ConsoleAppender
The appender has been commented out, to illustrate the bug.
Stack trace from log4j 2.17.1:
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)
Attachments
Attachments
Issue Links
- links to