fix: null-check LoggerDynamicMBean addAppender instantiation#4185
Open
SebTardif wants to merge 2 commits into
Open
fix: null-check LoggerDynamicMBean addAppender instantiation#4185SebTardif wants to merge 2 commits into
SebTardif wants to merge 2 commits into
Conversation
OptionConverter.instantiateByClassName returns null when the class is missing or not an Appender. addAppender immediately called setName and NPE'd on invalid JMX addAppender class names. Skip attach and log an error instead.
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.
LoggerDynamicMBean.addAppender(log4j-1.2-api JMX) callsOptionConverter.instantiateByClassName(..., null)and immediately uses the result. When the class name is invalid or not anAppender, instantiation returnsnulland the next line NPEs onappender.setName(...). That reaches the host through the JMXaddAppenderoperation with a bad class name.Failure scenario
OptionConverter.instantiateByClassNamealready logs and returns the default (null) onReflectiveOperationExceptionor assignability failure. The JMX facade must treat that as "do not attach," not as a hard crash.Fix
cat.error(...)and return without attaching.AppenderDynamicMBean.setLayouthas the same instantiate pattern, butregisterLayoutMBeanalready returns early whenlayout == null. No change needed there.Red / green
Also covers the happy path: valid
ConsoleAppenderclass still attaches under the given name.Checklist
2.xsrc/changelog/.2.x.x/fix_logger_dynamic_mbean_null_appender.xmlLoggerDynamicMBeanTest(JUnit 5, same package as package-privateaddAppender)./mvnw spotless:check -pl log4j-1.2-api -amcleanRelated: same null-from-instantiate class as #4172 (XmlConfiguration
parseAppender).