[KARAF-6146] Fix potential NPE in alerter 71/head
authorJean-Baptiste Onofré <jb@nanthrax.net>
Sun, 10 Feb 2019 08:14:34 +0000 (09:14 +0100)
committerJean-Baptiste Onofré <jb@nanthrax.net>
Sun, 10 Feb 2019 08:14:34 +0000 (09:14 +0100)
alerting/alerter/log/src/main/java/org/apache/karaf/decanter/alerting/log/Logger.java
collector/eventadmin/src/main/java/org/apache/karaf/decanter/collector/eventadmin/EventCollector.java

index bcf5deb..151069c 100644 (file)
@@ -35,7 +35,8 @@ public class Logger implements EventHandler {
     public void handleEvent(Event event) {
         StringBuilder builder = new StringBuilder();
         for (String innerKey : event.getPropertyNames()) {
-            builder.append(innerKey).append(":").append(event.getProperty(innerKey).toString()).append(" | ");
+            String value = (event.getProperty(innerKey) != null) ? event.getProperty(innerKey).toString() : null;
+            builder.append(innerKey).append(":").append(value).append(" | ");
         }
         boolean backToNormal = (boolean) event.getProperty("alertBackToNormal");
         if (event.getProperty("alertLevel") != null && ((String) event.getProperty("alertLevel")).equalsIgnoreCase("error")) {
index f23e651..44d79b0 100644 (file)
@@ -54,7 +54,7 @@ public class EventCollector implements EventHandler {
         for (String property : event.getPropertyNames()) {
             if (property.equals("type")) {
                 if (event.getProperty(property) != null) {
-                    data.put("eventType", event.getProperty(property).toString());
+                    data.put("eventType", (event.getProperty(property) != null) ? event.getProperty(property).toString() : null);
                 } else {
                     data.put("eventType", "eventadmin");
                 }