[
https://issues.apache.org/jira/browse/LOG4J2-2316?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16551742#comment-16551742
]
Gary Gregory edited comment on LOG4J2-2316 at 7/21/18 3:45 PM:
---------------------------------------------------------------
Question to the community:
In the method
{{org.apache.logging.log4j.core.config.LoggerConfig.logParent(LogEvent,
LoggerConfigPredicate)}} we check for a null parent which seems to mean that we
allow for a null {{LoggerConfig}} parent.
This leads me to ask: What is the difference between a null {{LoggerConfig}}
and a {{LoggerConfig}} for the root logger ({{""}})?
As an experiment I changed LoggerConfig setParent() in git {{release-2.x}} to:
{code:java}
public void setParent(final LoggerConfig parent) {
this.parent = Objects.requireNonNull(parent, "parent");
}
{code}
A full build with {{mvn clean install}} succeeds but that means that we don't
have the kind of test that duplicates the above problem, probably.
We could alternatively add a null check in
{{org.apache.logging.log4j.core.config.LoggerConfig.getLevel()}} but that would
only pass the buck on the NPE to call sites of {{getLevel()}} and not help us
here.
My inclination is to update LoggerConfig to not allow setParent to accept null
and see what happens for [~Ranjit.Dsouza]; we should see a new NPE from where
the null parent comes from...
Final question then: Should LoggerConfig allow a null parent?
Thoughts?
was (Author: garydgregory):
Question to the community:
In the method
{{org.apache.logging.log4j.core.config.LoggerConfig.logParent(LogEvent,
LoggerConfigPredicate)}} we check for a null parent which seems to mean that we
allow for a null {{LoggerConfig}} parent.
This leads me to ask: What is the difference between a null {{LoggerConfig}}
and a {{LoggerConfig}} for the root logger ({{""}})?
As an experiment I changed LoggerConfig setParent to:
{code:java}
public void setParent(final LoggerConfig parent) {
this.parent = Objects.requireNonNull(parent, "parent");
}
{code}
A full build with {{mvn clean install}} succeeds but that means that we don't
have the kind of test that duplicates the above problem, probably.
We could alternatively add a null check in
{{org.apache.logging.log4j.core.config.LoggerConfig.getLevel()}} but that would
only pass the buck on the NPE to call sites of {{getLevel()}} and not help us
here.
My inclination is to update LoggerConfig to not allow setParent to accept null
and see what happens for [~Ranjit.Dsouza]; we should see a new NPE from where
the null parent comes from...
Final question then: Should LoggerConfig allow a null parent?
Thoughts?
> NullPointerException while calling Configurator.setLevel()
> ----------------------------------------------------------
>
> Key: LOG4J2-2316
> URL: https://issues.apache.org/jira/browse/LOG4J2-2316
> Project: Log4j 2
> Issue Type: Bug
> Components: Core, Web/Servlet
> Affects Versions: 2.11.0
> Environment: webapplication running in tomcat 8.5
> Reporter: Ranjit Dsouza
> Priority: Major
>
> Hi I want to report an intermittent issue in my webapplication wherein log4j
> throws an NPE.
> Here is the stack trace:
> java.lang.NullPointerException
> at
> org.apache.logging.log4j.core.config.LoggerConfig.getLevel(LoggerConfig.java:268)
> at
> org.apache.logging.log4j.core.Logger$PrivateConfig.<init>(Logger.java:384)
> at
> org.apache.logging.log4j.core.Logger.updateConfiguration(Logger.java:365)
> at
> org.apache.logging.log4j.core.LoggerContext.updateLoggers(LoggerContext.java:652)
> at
> org.apache.logging.log4j.core.LoggerContext.updateLoggers(LoggerContext.java:641)
> at
> org.apache.logging.log4j.core.config.Configurator.setLevel(Configurator.java:296)
> at
> com.netbackup.logging.util.DebugLoggerFactory.getLogger(DebugLoggerFactory.java:346)
> at
> com.netbackup.logging.util.DebugLoggerFactory.getLogger(DebugLoggerFactory.java:359)
> at
> com.netbackup.logging.util.WebServiceLoggerFactory.getLogger(WebServiceLoggerFactory.java:14)
> at
> com.netbackup.common.logging.LoggerFactory.getLogger(LoggerFactory.java:34)
>
> Log4j code where the NPE occurs: (LoggerConfig.java)
> /**
> * Returns the logging Level.
> *
> * @return the logging Level.
> */
> public Level getLevel()
> { return level == null ? parent.getLevel() : level; } //This is
> the line where the NPE gets thrown
>
> Inference is parent(LoggerConfig) itself was null. When can this situation
> arise?
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)