From 98296cd1cc5e479d5b6e382307c0a6c8ccac142f Mon Sep 17 00:00:00 2001 From: Alexandre Montplaisir Date: Thu, 2 Jun 2016 05:22:13 -0400 Subject: [PATCH] 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 --- .../org/lttng/ust/agent/log4j/LttngLog4jAgent.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) 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; + } } } -- 2.34.1