From 187d89d3e7f80f79f50eea6f70f3a0a937aaf67e Mon Sep 17 00:00:00 2001 From: Alexandre Montplaisir Date: Thu, 19 May 2016 14:49:06 -0400 Subject: [PATCH] Fix: Avoid potential null dereference with log4j loggers Coverity warns that the return of LogManager.getCurrentLoggers() can contain null elements. Add an explicit null check to skip those. Signed-off-by: Alexandre Montplaisir Signed-off-by: Mathieu Desnoyers --- .../org/lttng/ust/agent/log4j/LttngLog4jAgent.java | 4 ++++ 1 file changed, 4 insertions(+) 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 7dcff9ec..6cb74f91 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 @@ -55,6 +55,10 @@ class LttngLog4jAgent extends AbstractLttngAgent { @SuppressWarnings("unchecked") List loggers = Collections.list(LogManager.getCurrentLoggers()); for (Logger logger : loggers) { + if (logger == null) { + continue; + } + /* * Check if that logger has at least one LTTng log4j appender * attached. -- 2.34.1