Skip to content

Commit

Permalink
Merge pull request #6187 from eclipse/jetty-9.4.x-6186-no-null-logger
Browse files Browse the repository at this point in the history
Issue #6186 - Add null protection to Log/Logger API
  • Loading branch information
joakime committed Apr 21, 2021
2 parents a4124b4 + ee29860 commit b15b37f
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions jetty-util/src/main/java/org/eclipse/jetty/util/log/Log.java
Expand Up @@ -28,6 +28,7 @@
import java.util.Enumeration;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.Properties;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
Expand Down Expand Up @@ -168,6 +169,7 @@ public static void initialized()
if (announce && LOG != null)
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)
Expand Down Expand Up @@ -195,7 +197,7 @@ public static Logger getLog()
*/
public static void setLog(Logger log)
{
Log.LOG = log;
Log.LOG = Objects.requireNonNull(log, "Root Logger may not be null");
__logClass = null;
}

Expand Down Expand Up @@ -275,13 +277,22 @@ public static Logger getLogger(String name)
{
initialized();

Logger logger = null;

// Return root
if (name == null)
return LOG;
logger = LOG;

Logger logger = __loggers.get(name);
// use cache
if (logger == null)
logger = __loggers.get(name);

// create new logger
if (logger == null && LOG != null)
logger = LOG.getLogger(name);

Objects.requireNonNull(logger, "Logger with name [" + name + "]");

return logger;
}

Expand Down

0 comments on commit b15b37f

Please sign in to comment.