/**
 * PtMatchAdapter - a patient matching system adapter
 * Copyright (C) 2016 The MITRE Corporation.  ALl rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.mitre.ptmatchadapter;

import java.util.LinkedList;
import java.util.List;

import org.hl7.fhir.instance.model.Bundle;
import org.hl7.fhir.instance.model.Bundle.BundleEntryComponent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.hl7.fhir.instance.model.Resource;
import org.springframework.stereotype.Component;

/**
 * @author Michael Los, mel@mitre.org
 *
 */
@Component
public class SearchResultSplitter {
  private static final Logger LOG = LoggerFactory.getLogger(SearchResultSplitter.class);

  /**
   * Breaks apart the given bundle into a list of Resources.
   * 
   * @param bundle
   *          the payload of the incoming message
   * @return a list containing each resource in the Bundle
   */
  public List<Resource> splitBundle(Bundle bundle) {
    final List<BundleEntryComponent> entries = bundle.getEntry();

    final List<Resource> resources = new LinkedList<Resource>();
    for (BundleEntryComponent entry : entries) {
      Resource r = entry.getResource();
      if (r != null) {
        LOG.debug("processing resource: " + r.getId());
        resources.add(r);
      } else {
        LOG.warn("Entry does not have a resource, fullUrl: {}", entry.getFullUrl());
      }
    }

    return resources;
  }
}

@@ -1172,16 +1172,23 @@
 rFactory
+%0A      
 .getLogg
@@ -1499,125 +1499,160 @@
 ist%3C
-BundleEntryComponent%3E entries = bundle.getEntry();%0A%0A    final List%3CResource%3E resources = new LinkedList%3CResource%3E
+Resource%3E resources = new LinkedList%3CResource%3E();%0A    %0A    if (bundle != null) %7B%0A      final List%3CBundleEntryComponent%3E entries = bundle.getEntry
 ();%0A
+%0A  
     
@@ -1702,16 +1702,18 @@
 %7B%0A      
+ 
+ 
 Resource
@@ -1734,24 +1734,26 @@
 Resource();%0A
+  
       if (r 
@@ -1767,24 +1767,26 @@
 ) %7B%0A        
+  
 LOG.debug(%22p
@@ -1829,16 +1829,18 @@
         
+ 
+ 
 resource
@@ -1855,16 +1855,18 @@
 ;%0A      
+  
 %7D else %7B
@@ -1866,16 +1866,18 @@
  else %7B%0A
+  
         
@@ -1931,16 +1931,30 @@
 rl: %7B%7D%22,
+%0A             
  entry.g
@@ -1963,24 +1963,34 @@
 FullUrl());%0A
+        %7D%0A
       %7D%0A    
@@ -1991,16 +1991,20 @@
 %7D%0A    %7D%0A
+    
 %0A    ret

Check for null bundle before trying to split into component parts.