Fix: Avoid potential null dereference with log4j loggers
authorAlexandre Montplaisir <alexmonthy@efficios.com>
Thu, 19 May 2016 18:49:06 +0000 (14:49 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Thu, 19 May 2016 19:50:52 +0000 (15:50 -0400)
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 <alexmonthy@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
liblttng-ust-java-agent/java/lttng-ust-agent-log4j/org/lttng/ust/agent/log4j/LttngLog4jAgent.java

index 7dcff9ec4e582721eba2c85675d56671884aa390..6cb74f91b5516864c1cc35403a1e8ff525cdda38 100644 (file)
@@ -55,6 +55,10 @@ class LttngLog4jAgent extends AbstractLttngAgent<LttngLogAppender> {
                @SuppressWarnings("unchecked")
                List<Logger> 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.
This page took 0.025759 seconds and 4 git commands to generate.