Details
-
Improvement
-
Status: Resolved
-
Major
-
Resolution: Fixed
-
2.6, 2.6.1, 2.6.2
-
None
Description
Don't throw an NPE from org.apache.logging.log4j.core.LoggerContext.setConfiguration(Configuration) when the configuration is missing.
I am seeing this in a customer use case with what the customer says is version "2.6.x."
The method org.apache.logging.log4j.core.LoggerContext.setConfiguration(Configuration) throws an exception when the given Configuration is null.
This can happen when the method is called by org.apache.logging.log4j.core.LoggerContext.reconfigure(URI) and the file backing the URI has disappeared.
Thoughts?
I propose that we either:
- Log an ERROR from org.apache.logging.log4j.core.LoggerContext.setConfiguration(Configuration) instead of throwing an NPE; or
- Change the implementation of org.apache.logging.log4j.core.LoggerContext.reconfigure(URI) to check for a null answer from ConfigurationFactory.getInstance().getConfiguration(contextName, configURI, cl); and log an ERROR if null.
- Do both (the best IMO.)
The exception I've see is (I had to change some class names and package names):
> Name: java.lang.NullPointerException > Message: No Configuration was provided > StackTrace: java.util.Objects.requireNonNull(Objects.java:228) > org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:477) > org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:561) > org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:577) > org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:212) > org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:152) > org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:45) > org.apache.logging.log4j.LogManager.getContext(LogManager.java:194) > com.example.log.MyLoggerHelperFactory.getLoggerContext(MyLoggerHelperFactory.java:79) > com.example.log.MyLoggerHelperFactory.getFormatterLogger(MyLoggerHelperFactory.java:73) > com.example.log.MyLoggerHelperFactory.getFormatterLogger(MyLoggerHelperFactory.java:68) > com.example.MyLoggerHelper.<init>(MyLoggerHelper.java:67) > com.example.MyLoggerHelper.<init>(MyLoggerHelper.java:57) > com.example.MyAbstractObject.<init>(MyAbstractObject.java:27) > com.example.MyMain.<init>(MyMain.java:125) > com.example.MyMain.<clinit>(MyMain.java:24) > sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) > sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) > sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) > sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) > sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) > java.lang.reflect.Constructor.newInstance(Constructor.java:408) > java.lang.Class.newInstance(Class.java:433) > org.apache.spark.sql.execution.datasources.jdbc.DriverRegistry$.register(DriverRegistry.scala:46) > org.apache.spark.sql.execution.datasources.jdbc.DefaultSource.createRelation(DefaultSource.scala:41) > org.apache.spark.sql.execution.datasources.ResolvedDataSource$.apply(ResolvedDataSource.scala:125) > org.apache.spark.sql.DataFrameReader.load(DataFrameReader.scala:114) > $line86.$read$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC.<init>(<console>:49) > $line86.$read$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC.<init>(<console>:54) > $line86.$read$$iwC$$iwC$$iwC$$iwC$$iwC.<init>(<console>:56) > $line86.$read$$iwC$$iwC$$iwC$$iwC.<init>(<console>:58) > $line86.$read$$iwC$$iwC$$iwC.<init>(<console>:60) > $line86.$read$$iwC$$iwC.<init>(<console>:62) > $line86.$read$$iwC.<init>(<console>:64) > $line86.$read.<init>(<console>:66) > $line86.$read$.<init>(<console>:70) > $line86.$read$.<clinit>(<console>) > $line86.$eval$.<init>(<console>:7) > $line86.$eval$.<clinit>(<console>) > $line86.$eval.$print(<console>) > sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) > sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) > sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) > java.lang.reflect.Method.invoke(Method.java:483) > org.apache.spark.repl.SparkIMain$ReadEvalPrint.call(SparkIMain.scala:1065) > org.apache.spark.repl.SparkIMain$Request.loadAndRun(SparkIMain.scala:1340) > org.apache.spark.repl.SparkIMain.loadAndRunReq$1(SparkIMain.scala:840) > org.apache.spark.repl.SparkIMain.interpret(SparkIMain.scala:871) > org.apache.spark.repl.SparkIMain.interpret(SparkIMain.scala:819) > org.apache.toree.kernel.interpreter.scala.ScalaInterpreter$$anonfun$interpretAddTask$1$$anonfun$apply$3.apply(ScalaInterpreter.scala:361) > org.apache.toree.kernel.interpreter.scala.ScalaInterpreter$$anonfun$interpretAddTask$1$$anonfun$apply$3.apply(ScalaInterpreter.scala:356) > org.apache.toree.global.StreamState$.withStreams(StreamState.scala:81) > org.apache.toree.kernel.interpreter.scala.ScalaInterpreter$$anonfun$interpretAddTask$1.apply(ScalaInterpreter.scala:355) > org.apache.toree.kernel.interpreter.scala.ScalaInterpreter$$anonfun$interpretAddTask$1.apply(ScalaInterpreter.scala:355) > org.apache.toree.utils.TaskManager$$anonfun$add$2$$anon$1.run(TaskManager.scala:140) > java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) > java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) > java.lang.Thread.run(Thread.java:745)