killbill-uncached

invoice: Fix potential NPE when there is no item to be removed

11/6/2016 10:13:57 PM

Details

diff --git a/invoice/src/main/java/org/killbill/billing/invoice/tree/ItemsNodeInterval.java b/invoice/src/main/java/org/killbill/billing/invoice/tree/ItemsNodeInterval.java
index e3f9af0..12bad8b 100644
--- a/invoice/src/main/java/org/killbill/billing/invoice/tree/ItemsNodeInterval.java
+++ b/invoice/src/main/java/org/killbill/billing/invoice/tree/ItemsNodeInterval.java
@@ -307,7 +307,7 @@ public class ItemsNodeInterval extends NodeInterval {
                 }
 
                 // Case B -- look for such case, and if found (foundFullRepairByParts) we fix them below.
-                List<Item> curNodeItemsToBeRemoved = null;
+                List<Item> curNodeItemsToBeRemoved = new ArrayList<Item>();
                 final Iterator<Item> it = curNodeItems.get_ADD_items().iterator();
                 // For each item on this curNode interval we check if there is a matching set of CANCEL items on the children (resulting in completely cancelling that item).
                 while (it.hasNext()) {
@@ -341,9 +341,6 @@ public class ItemsNodeInterval extends NodeInterval {
                                 curNode.removeChild(curItemsInterval.getNodeInterval());
                             }
                         }
-                        if (curNodeItemsToBeRemoved == null) {
-                            curNodeItemsToBeRemoved = new ArrayList<Item>();
-                        }
                         curNodeItemsToBeRemoved.add(curAddItem);
                     }
                 }