-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Avoid NPE from ContextSelector.getContext() when "entry=null" is passed #1538
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
This fixes an apparent bug which was reported already in https://issues.apache.org/jira/browse/LOG4J2-3217. Note that only `ClassLoaderContextSelector` provided a custom implementation of this method, where it also checks for null-ness of `entry`. So all other selector classes like `BasicContextSelector ` would throw NullPointerException when e.g. `Configurator.initialize(String, ClassLoader, URI)` is called.
Note: I've across this issue when trying to deactivate asynchronous logging as described in CAS documentation:
Even after doing this and fixing the NPE, CAS still logs asynchronously, but that is possibly for another bug, possibly in another repository. 😅 Regarding unit tests and changelog - I'm not sure. Let me know if it is needed. |
@pbodnar, thanks so much! I will take care of the changelog.
That indeed warrants another ticket. |
@@ -108,7 +108,7 @@ default LoggerContext getContext(String fqcn, ClassLoader loader, Map.Entry<Stri | |||
default LoggerContext getContext(String fqcn, ClassLoader loader, Map.Entry<String, Object> entry, | |||
boolean currentContext, URI configLocation) { | |||
final LoggerContext lc = getContext(fqcn, loader, currentContext, configLocation); | |||
if (lc != null) { | |||
if (lc != null && entry != 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.
lc
should be not null
here, we just need to check if entry
is not 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.
Since getContext()
is to be implemented by the subclass, I thought we cannot have such an assumption. Nevertheless, if you think otherwise, be my guest to update it.
This fixes an apparent bug which was reported already in https://issues.apache.org/jira/browse/LOG4J2-3217.
Note that only
ClassLoaderContextSelector
provided a custom implementation of this method, where it also checks for null-ness ofentry
. So all other selector classes likeBasicContextSelector
would throw NullPointerException when e.g.Configurator.initialize(String, ClassLoader, URI)
is called.