-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
LOG4J2-3407 Log4j 1.2 bridge Check for non-existent appender when parsing properties #761
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
Conversation
| if (className == null) { | ||
| LOGGER.debug("Appender \"" + appenderName + "\" does not exist."); | ||
| return null; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without this null-check, there will be a NPE from the next line down.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remark also that Log4j 1.x behaves differently
- whenever any component has an empty property the error "Could not find value for key ..." is logged (cf. source code.
- then there is a message "Could not instantiate appender named ..." (cf. source code). This should probably be checked just before the return statement. Remark that appender instantiation can also fail if some other properties are missing (e.g.
Filefor the file appender).
| log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout | ||
| log4j.appender.CONSOLE.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n | ||
|
|
||
| log4j.logger.org.apache.log4j.xml=trace, A1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here we have a logger referring to an appender (A1) that does not exist
| try (LoggerContext loggerContext = TestConfigurator.configure("target/test-classes/LOG4J2-3407.properties")) { | ||
| final Configuration configuration = loggerContext.getConfiguration(); | ||
| assertNotNull(configuration); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test fails with an NPE without the fix
This change will make
PropertiesConfigurationtolerant of attempts to resolve a non-existent Appender. See JIRA ticket for details.