Fix: Null-check return value of log4j.Category.getAllAppenders()
authorAlexandre Montplaisir <alexmonthy@efficios.com>
Thu, 2 Jun 2016 09:22:13 +0000 (05:22 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Thu, 2 Jun 2016 13:20:49 +0000 (15:20 +0200)
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 <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 7677e68ee66e2b2c20773e0675654d24e49f7f46..157ff3fe879395b88b1d0592805537201457a02c 100644 (file)
@@ -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<LttngLogAppender> {
 
        private static boolean hasLttngAppenderAttached(Category logger) {
                @SuppressWarnings("unchecked")
-               List<Appender> appenders = Collections.list(logger.getAllAppenders());
-               for (Appender appender : appenders) {
-                       if (appender instanceof LttngLogAppender) {
-                               return true;
+               Enumeration<Appender> appenders = logger.getAllAppenders();
+               if (appenders != null) {
+                       for (Appender appender : Collections.list(appenders)) {
+                               if (appender instanceof LttngLogAppender) {
+                                       return true;
+                               }
                        }
                }
 
This page took 0.02537 seconds and 4 git commands to generate.