[LOG4J2-2417] handle null properties

Project: http://git-wip-us.apache.org/repos/asf/logging-log4j-audit/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/logging-log4j-audit/commit/02529bb7
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j-audit/tree/02529bb7
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j-audit/diff/02529bb7

Branch: refs/heads/master
Commit: 02529bb74a58b87643867c2df7731b402f9f5f86
Parents: 3e3bf9d
Author: Andrei Ivanov <[email protected]>
Authored: Mon Sep 17 15:10:06 2018 +0300
Committer: Andrei Ivanov <[email protected]>
Committed: Mon Sep 17 15:10:06 2018 +0300

----------------------------------------------------------------------
 .../logging/log4j/audit/LogEventFactory.java    | 11 +++++-----
 .../apache/logging/log4j/audit/LoginTest.java   | 21 ++++++++++++++++++++
 2 files changed, 27 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j-audit/blob/02529bb7/log4j-audit/log4j-audit-api/src/main/java/org/apache/logging/log4j/audit/LogEventFactory.java
----------------------------------------------------------------------
diff --git 
a/log4j-audit/log4j-audit-api/src/main/java/org/apache/logging/log4j/audit/LogEventFactory.java
 
b/log4j-audit/log4j-audit-api/src/main/java/org/apache/logging/log4j/audit/LogEventFactory.java
index d275335..9617956 100644
--- 
a/log4j-audit/log4j-audit-api/src/main/java/org/apache/logging/log4j/audit/LogEventFactory.java
+++ 
b/log4j-audit/log4j-audit-api/src/main/java/org/apache/logging/log4j/audit/LogEventFactory.java
@@ -20,10 +20,7 @@ import java.lang.annotation.Annotation;
 import java.lang.reflect.InvocationHandler;
 import java.lang.reflect.Method;
 import java.lang.reflect.Proxy;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
 
@@ -130,10 +127,14 @@ public class LogEventFactory {
         String eventId = NamingUtils.lowerFirst(intrface.getSimpleName());
         int maxLength = getMaxLength(intrface);
         AuditMessage msg = new AuditMessage(eventId, maxLength);
+
+        if (properties == null) {
+            properties = Collections.emptyMap();
+        }
         List<Property> props = getProperties(intrface);
         Map<String, Property> propertyMap = new HashMap<>();
 
-        for (Property property : props ) {
+        for (Property property : props) {
             propertyMap.put(property.name, property);
             if (property.isRequired && !properties.containsKey(property.name)) 
{
                 if (errors.length() > 0) {

http://git-wip-us.apache.org/repos/asf/logging-log4j-audit/blob/02529bb7/log4j-audit/log4j-audit-api/src/test/java/org/apache/logging/log4j/audit/LoginTest.java
----------------------------------------------------------------------
diff --git 
a/log4j-audit/log4j-audit-api/src/test/java/org/apache/logging/log4j/audit/LoginTest.java
 
b/log4j-audit/log4j-audit-api/src/test/java/org/apache/logging/log4j/audit/LoginTest.java
index c40a1cd..190ccd6 100644
--- 
a/log4j-audit/log4j-audit-api/src/test/java/org/apache/logging/log4j/audit/LoginTest.java
+++ 
b/log4j-audit/log4j-audit-api/src/test/java/org/apache/logging/log4j/audit/LoginTest.java
@@ -3,11 +3,32 @@ package org.apache.logging.log4j.audit;
 import org.apache.logging.log4j.audit.event.Login;
 import org.junit.Test;
 
+import java.util.Collections;
+import java.util.List;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
 public class LoginTest extends BaseEventTest {
     @Test
     public void testAuditClass() {
         Login event = LogEventFactory.getEvent(Login.class);
 
         event.logEvent();
+
+        event.setCompletionStatus("Success");
+
+        event.logEvent();
+
+        List<String> msgs = app.getMessages();
+        assertNotNull("No messages", msgs);
+        assertTrue("No messages", msgs.size() == 2);
+    }
+
+    @Test
+    public void testAuditLog() {
+        LogEventFactory.logEvent(Login.class, null);
+
+        LogEventFactory.logEvent(Login.class, Collections.emptyMap());
     }
 }
\ No newline at end of file

Reply via email to