Skip to content

Conversation

@kennymacleod
Copy link
Contributor

This change will make PropertiesConfiguration tolerant of attempts to resolve a non-existent Appender. See JIRA ticket for details.

if (className == null) {
LOGGER.debug("Appender \"" + appenderName + "\" does not exist.");
return null;
}
Copy link
Contributor Author

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.

Copy link
Contributor

@ppkarwasz ppkarwasz Feb 18, 2022

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. File for 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
Copy link
Contributor Author

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);
}
Copy link
Contributor Author

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

@apache apache deleted a comment Feb 18, 2022
@garydgregory garydgregory changed the title LOG4J2-3407 Check for non-existent appender when parsing properties LOG4J2-3407 Log4j 1.2 bridge Check for non-existent appender when parsing properties Feb 20, 2022
@garydgregory garydgregory merged commit 14fa165 into apache:release-2.x Feb 21, 2022
asfgit pushed a commit that referenced this pull request Feb 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants