Fix NPE in UpdateReq.reconfigure() 71/122471/1
authorJim Hahn <jrh3@att.com>
Tue, 6 Jul 2021 20:03:22 +0000 (16:03 -0400)
committerJim Hahn <jrh3@att.com>
Tue, 6 Jul 2021 20:24:57 +0000 (16:24 -0400)
While running CSIT to test heartbeat changes with multiple PAPs,
observed an NPE in UpdateReq.reconfigure().  Modified the code to
always use deployment lists instead of null lists.

Issue-ID: POLICY-3460
Change-Id: I884e091817e88309330139a01d060e286bd42008
Signed-off-by: Jim Hahn <jrh3@att.com>
main/src/main/java/org/onap/policy/pap/main/comm/msgdata/UpdateReq.java
main/src/test/java/org/onap/policy/pap/main/comm/msgdata/UpdateReqTest.java

index eeed5fc..6f62cf2 100644 (file)
@@ -131,6 +131,10 @@ public class UpdateReq extends RequestImpl {
 
         PdpUpdate update = (PdpUpdate) newMessage;
 
+        // ensure lists are never null
+        update.setPoliciesToBeDeployed(alwaysList(update.getPoliciesToBeDeployed()));
+        update.setPoliciesToBeUndeployed(alwaysList(update.getPoliciesToBeUndeployed()));
+
         if (isSameContent(update)) {
             // content hasn't changed - nothing more to do
             return true;
index c318a03..6ea874d 100644 (file)
@@ -22,6 +22,7 @@
 package org.onap.policy.pap.main.comm.msgdata;
 
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatCode;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNull;
@@ -198,6 +199,16 @@ public class UpdateReqTest extends CommonRequestBase {
         msg2.setPdpGroup(DIFFERENT);
         assertTrue(data.reconfigure(msg2));
         assertSame(msg2, data.getMessage());
+
+        // both lists in the update are null - should not throw an exception
+        PdpUpdate msg3 = new PdpUpdate(update);
+        msg3.setPdpGroup(DIFFERENT);
+        msg3.setPoliciesToBeDeployed(null);
+        msg3.setPoliciesToBeUndeployed(null);
+        assertThatCode(() -> data.reconfigure(msg3)).doesNotThrowAnyException();
+
+        // both lists in the current msg (i.e., msg3) are null - should not throw an exception
+        assertThatCode(() -> data.reconfigure(update)).doesNotThrowAnyException();
     }
 
     @Test