Minor NPE fix for auditlogging 65/1365/1
authorjsimomaa <jani.simomaa@gmail.com>
Tue, 9 Jan 2018 12:51:02 +0000 (14:51 +0200)
committerjsimomaa <jani.simomaa@gmail.com>
Tue, 9 Jan 2018 12:51:02 +0000 (14:51 +0200)
refs #7684

Change-Id: I86f892bf133b1965d9631ce82ddf02b78ec88a5a

bundles/org.simantics.auditlogging/src/org/simantics/audit/client/AuditLoggingClient.java

index 63045fdcfe7a3f598751a7207b2d2d12c2a01950..e9043187d76db1c28b5325292b4ce38a7848412c 100644 (file)
@@ -91,21 +91,22 @@ public class AuditLoggingClient {
 
     private static void commit(Level level, Map<String, Object> message) throws AuditLoggingException {
         try {
-            AuditLoggingAPIClient client = fromEnv().apiClient;
-            if (client == null) {
+            AuditLoggingClient client = fromEnv();
+            if (client == null || client.apiClient == null) {
                 // No can do - at least log to file
                 LOGGER.warn("Audit logging server not configured - printing event to log");
                 LOGGER.info(message.toString());
             } else {
+                AuditLoggingAPIClient apiClient = client.apiClient;
                 switch (level) {
                 case INFO:
-                    client.log(message);
+                    apiClient.log(message);
                     break;
                 case ERROR:
-                    client.error(message);
+                    apiClient.error(message);
                     break;
                 case TRACE:
-                    client.trace(message);
+                    apiClient.trace(message);
                     break;
                 default:
                     break;