Merge pull request #6187 from eclipse/jetty-9.4.x-6186-no-null-logger
Issue #6186 - Add null protection to Log/Logger API
This commit is contained in:
commit
b15b37f944
|
@ -28,6 +28,7 @@ import java.util.Collections;
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.ConcurrentMap;
|
import java.util.concurrent.ConcurrentMap;
|
||||||
|
@ -168,6 +169,7 @@ public class Log
|
||||||
if (announce && LOG != null)
|
if (announce && LOG != null)
|
||||||
LOG.info(String.format("Logging initialized @%dms to %s", Uptime.getUptime(), LOG.getClass().getName()));
|
LOG.info(String.format("Logging initialized @%dms to %s", Uptime.getUptime(), LOG.getClass().getName()));
|
||||||
}
|
}
|
||||||
|
Objects.requireNonNull(LOG, "Root Logger may not be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void initStandardLogging(Throwable e)
|
private static void initStandardLogging(Throwable e)
|
||||||
|
@ -195,7 +197,7 @@ public class Log
|
||||||
*/
|
*/
|
||||||
public static void setLog(Logger log)
|
public static void setLog(Logger log)
|
||||||
{
|
{
|
||||||
Log.LOG = log;
|
Log.LOG = Objects.requireNonNull(log, "Root Logger may not be null");
|
||||||
__logClass = null;
|
__logClass = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -275,13 +277,22 @@ public class Log
|
||||||
{
|
{
|
||||||
initialized();
|
initialized();
|
||||||
|
|
||||||
if (name == null)
|
Logger logger = null;
|
||||||
return LOG;
|
|
||||||
|
|
||||||
Logger logger = __loggers.get(name);
|
// Return root
|
||||||
|
if (name == null)
|
||||||
|
logger = LOG;
|
||||||
|
|
||||||
|
// use cache
|
||||||
if (logger == null)
|
if (logger == null)
|
||||||
|
logger = __loggers.get(name);
|
||||||
|
|
||||||
|
// create new logger
|
||||||
|
if (logger == null && LOG != null)
|
||||||
logger = LOG.getLogger(name);
|
logger = LOG.getLogger(name);
|
||||||
|
|
||||||
|
Objects.requireNonNull(logger, "Logger with name [" + name + "]");
|
||||||
|
|
||||||
return logger;
|
return logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue