From: Alexandre Montplaisir Date: Thu, 2 Jun 2016 09:22:13 +0000 (-0400) Subject: Fix: Null-check return value of log4j.Category.getAllAppenders() X-Git-Tag: v2.8.1~2 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=98296cd1cc5e479d5b6e382307c0a6c8ccac142f;p=lttng-ust.git Fix: Null-check return value of log4j.Category.getAllAppenders() Coverity points out this can be null, null-check it to be safe. If it in indeed null, we must still continue on to verify the parent loggers. Signed-off-by: Alexandre Montplaisir Signed-off-by: Mathieu Desnoyers --- diff --git a/liblttng-ust-java-agent/java/lttng-ust-agent-log4j/org/lttng/ust/agent/log4j/LttngLog4jAgent.java b/liblttng-ust-java-agent/java/lttng-ust-agent-log4j/org/lttng/ust/agent/log4j/LttngLog4jAgent.java index 7677e68e..157ff3fe 100644 --- a/liblttng-ust-java-agent/java/lttng-ust-agent-log4j/org/lttng/ust/agent/log4j/LttngLog4jAgent.java +++ b/liblttng-ust-java-agent/java/lttng-ust-agent-log4j/org/lttng/ust/agent/log4j/LttngLog4jAgent.java @@ -19,6 +19,7 @@ package org.lttng.ust.agent.log4j; import java.util.Collection; import java.util.Collections; +import java.util.Enumeration; import java.util.List; import java.util.Set; import java.util.TreeSet; @@ -75,10 +76,12 @@ class LttngLog4jAgent extends AbstractLttngAgent { private static boolean hasLttngAppenderAttached(Category logger) { @SuppressWarnings("unchecked") - List appenders = Collections.list(logger.getAllAppenders()); - for (Appender appender : appenders) { - if (appender instanceof LttngLogAppender) { - return true; + Enumeration appenders = logger.getAllAppenders(); + if (appenders != null) { + for (Appender appender : Collections.list(appenders)) { + if (appender instanceof LttngLogAppender) { + return true; + } } }