Repository navigation
Respect putIfAbsent results and null arguments in AbstractConfiguration logger mutators - #4423
Closed
sharanggupta wants to merge 1 commit into
Closed
sharanggupta wants to merge 1 commit into
sharanggupta wants to merge 1 commit into
Conversation
…on logger mutators addLoggerAppender attached an appender instance that was not registered when another appender with the same name already was, so the logger wrote to an instance the configuration never started or stopped. Attach the registered instance instead, respect the result of the loggerConfigs putIfAbsent in all three methods, and ignore null arguments in addLoggerFilter and setLoggerAdditive like addLoggerAppender does. Closes apache#3155
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3155.
AbstractConfiguration.addLoggerAppender,addLoggerFilterandsetLoggerAdditive(the implementation behindcore.Logger#addAppender,#addFilterand#setAdditive) ignored the result of theirputIfAbsentcalls:addLoggerAppender: when a different appender instance was already registered under the same name, the new instance was not registered but was still attached to theLoggerConfig, so the logger wrote to an appender the configuration never started or stopped whilegetAppender(name)returned another one. The registered instance is now attached instead (first wins, asaddAppenderalready behaves), with a status-logger warning.loggerConfigs.putIfAbsent(loggerName, nlc)is respected; when a config already exists the change is applied to it instead of re-wiring the parents and updating the loggers again. Under the method lock and the exact-name lookup that precedes it this branch is defensive, so it has no test of its own.addLoggerFilterandsetLoggerAdditivenow ignorenullarguments likeaddLoggerAppenderdoes, instead of throwingNullPointerException(side note 1 in the issue).Tests, one per method in
AbstractConfigurationTest: the duplicate-name appender case; the filter case (null arguments ignored, exactly oneLoggerConfigcreated with the right parent, both filters applied); the additive case (null logger ignored, one config created, additivity reflected by the logger). All three fail before the change and pass after. Changelog entry for 2.x included.Checklist
2.x./mvnw verifyonlog4j-core/log4j-core-testwithAbstractConfigurationTestsucceeds (spotless applied)src/changelog/.2.x.x