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.9.0-rc1~67 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=a548b3c1a329855ad7b2be6937a5a378419fb1b3;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; + } } }