Program: 115054
Project: 115054
Buggy source:
/** 
 * For each single item in this section which is a parent, get a DisplayItemBean corresponding to that item. Note that an item is a parent iff its parentId == 0.
 * @param sb The section whose items we are retrieving.
 * @param hasUngroupedItems
 * @param request TODO
 * @return An array of DisplayItemBean objects, one per parent item in the section. Note that there is no guarantee on the ordering of the objects.
 * @throws Exception
 */
private ArrayList getParentDisplayItems(boolean hasGroup,SectionBean sb,EventDefinitionCRFBean edcb,ItemDAO idao,ItemFormMetadataDAO ifmdao,ItemDataDAO iddao,boolean hasUngroupedItems,HttpServletRequest request) throws Exception {
  ArrayList answer=new ArrayList();
  EventCRFBean ecb=(EventCRFBean)request.getAttribute(INPUT_EVENT_CRF);
  HashMap displayItems=new HashMap();
  ArrayList items=new ArrayList();
  ArrayList itemsUngrped=new ArrayList();
  if (hasGroup) {
    if (hasUngroupedItems) {
      itemsUngrped=idao.findAllUngroupedParentsBySectionId(sb.getId(),sb.getCRFVersionId());
    }
  }
  LOGGER.trace("String_Node_Str");
  items=idao.findAllNonRepeatingParentsBySectionId(sb.getId());
  items.addAll(itemsUngrped);
  LOGGER.debug("String_Node_Str" + items.size());
  for (int i=0; i < items.size(); i++) {
    DisplayItemBean dib=new DisplayItemBean();
    dib.setEventDefinitionCRF(edcb);
    ItemBean ib=(ItemBean)items.get(i);
    dib.setItem(ib);
    displayItems.put(new Integer(dib.getItem().getId()),dib);
  }
  BeanUtils bu=new BeanUtils();
  ArrayList data=iddao.findAllBySectionIdAndEventCRFId(sb.getId(),ecb.getId());
  for (int i=0; i < data.size(); i++) {
    ItemDataBean idb=(ItemDataBean)data.get(i);
    DisplayItemBean dib=(DisplayItemBean)displayItems.get(new Integer(idb.getItemId()));
    if (dib != null) {
      dib.setData(idb);
      dib.setDbData((ItemDataBean)bu.cloneBean(idb));
      displayItems.put(new Integer(idb.getItemId()),dib);
    }
  }
  ArrayList metadata=ifmdao.findAllBySectionId(sb.getId());
  for (int i=0; i < metadata.size(); i++) {
    ItemFormMetadataBean ifmb=(ItemFormMetadataBean)metadata.get(i);
    DisplayItemBean dib=(DisplayItemBean)displayItems.get(new Integer(ifmb.getItemId()));
    if (dib != null) {
      boolean needsHighlighting=!ifmb.isShowItem();
      logMe("String_Node_Str" + Thread.currentThread());
      boolean showItem=getItemMetadataService().isShown(ifmb.getItemId(),ecb,dib.getData());
      if (getServletPage(request).equals(Page.DOUBLE_DATA_ENTRY_SERVLET)) {
        showItem=getItemMetadataService().hasPassedDDE(ifmb,ecb,dib.getData());
      }
      boolean passedDDE=getItemMetadataService().hasPassedDDE(ifmb,ecb,dib.getData());
      if (showItem) {
        LOGGER.debug("String_Node_Str" + ifmb.getItemId() + "String_Node_Str"+ dib.getData().getId()+ "String_Node_Str"+ showItem+ "String_Node_Str"+ passedDDE);
        ifmb.setShowItem(true);
      }
 else {
        LOGGER.debug("String_Node_Str" + ifmb.getItemId() + "String_Node_Str"+ dib.getData().getId()+ "String_Node_Str"+ showItem+ "String_Node_Str"+ passedDDE+ "String_Node_Str"+ dib.getData().getValue());
      }
      dib.setMetadata(ifmb);
      displayItems.put(new Integer(ifmb.getItemId()),dib);
    }
  }
  Iterator hmIt=displayItems.keySet().iterator();
  while (hmIt.hasNext()) {
    Integer key=(Integer)hmIt.next();
    DisplayItemBean dib=(DisplayItemBean)displayItems.get(key);
    answer.add(dib);
    LOGGER.debug("String_Node_Str" + key + "String_Node_Str"+ dib.getData().getValue());
  }
  LOGGER.debug("String_Node_Str" + displayItems.toString());
  return answer;
}

Fixed version (ground truth):
/** 
 * For each single item in this section which is a parent, get a DisplayItemBean corresponding to that item. Note that an item is a parent iff its parentId == 0.
 * @param sb The section whose items we are retrieving.
 * @param hasUngroupedItems
 * @param request TODO
 * @return An array of DisplayItemBean objects, one per parent item in the section. Note that there is no guarantee on the ordering of the objects.
 * @throws Exception
 */
private ArrayList getParentDisplayItems(boolean hasGroup,SectionBean sb,EventDefinitionCRFBean edcb,ItemDAO idao,ItemFormMetadataDAO ifmdao,ItemDataDAO iddao,boolean hasUngroupedItems,HttpServletRequest request) throws Exception {
  ArrayList answer=new ArrayList();
  EventCRFBean ecb=(EventCRFBean)request.getAttribute(INPUT_EVENT_CRF);
  HashMap displayItems=new HashMap();
  ArrayList items=new ArrayList();
  ArrayList itemsUngrped=new ArrayList();
  if (hasGroup) {
    if (hasUngroupedItems) {
      itemsUngrped=idao.findAllUngroupedParentsBySectionId(sb.getId(),sb.getCRFVersionId());
    }
  }
  LOGGER.trace("String_Node_Str");
  items=idao.findAllNonRepeatingParentsBySectionId(sb.getId());
  items.addAll(itemsUngrped);
  LOGGER.debug("String_Node_Str" + items.size());
  for (int i=0; i < items.size(); i++) {
    DisplayItemBean dib=new DisplayItemBean();
    dib.setEventDefinitionCRF(edcb);
    ItemBean ib=(ItemBean)items.get(i);
    dib.setItem(ib);
    displayItems.put(new Integer(dib.getItem().getId()),dib);
  }
  ArrayList data=iddao.findAllBySectionIdAndEventCRFId(sb.getId(),ecb.getId());
  for (int i=0; i < data.size(); i++) {
    ItemDataBean idb=(ItemDataBean)data.get(i);
    DisplayItemBean dib=(DisplayItemBean)displayItems.get(new Integer(idb.getItemId()));
    if (dib != null) {
      dib.setData(idb);
      dib.setDbData((ItemDataBean)BeanUtils.cloneBean(idb));
      displayItems.put(new Integer(idb.getItemId()),dib);
    }
  }
  ArrayList metadata=ifmdao.findAllBySectionId(sb.getId());
  for (int i=0; i < metadata.size(); i++) {
    ItemFormMetadataBean ifmb=(ItemFormMetadataBean)metadata.get(i);
    DisplayItemBean dib=(DisplayItemBean)displayItems.get(new Integer(ifmb.getItemId()));
    if (dib != null) {
      boolean needsHighlighting=!ifmb.isShowItem();
      logMe("String_Node_Str" + Thread.currentThread());
      boolean showItem=getItemMetadataService().isShown(ifmb.getItemId(),ecb,dib.getData());
      if (getServletPage(request).equals(Page.DOUBLE_DATA_ENTRY_SERVLET)) {
        showItem=getItemMetadataService().hasPassedDDE(ifmb,ecb,dib.getData());
      }
      boolean passedDDE=getItemMetadataService().hasPassedDDE(ifmb,ecb,dib.getData());
      if (showItem) {
        LOGGER.debug("String_Node_Str" + ifmb.getItemId() + "String_Node_Str"+ dib.getData().getId()+ "String_Node_Str"+ showItem+ "String_Node_Str"+ passedDDE);
        ifmb.setShowItem(true);
      }
 else {
        LOGGER.debug("String_Node_Str" + ifmb.getItemId() + "String_Node_Str"+ dib.getData().getId()+ "String_Node_Str"+ showItem+ "String_Node_Str"+ passedDDE+ "String_Node_Str"+ dib.getData().getValue());
      }
      dib.setMetadata(ifmb);
      displayItems.put(new Integer(ifmb.getItemId()),dib);
    }
  }
  Iterator hmIt=displayItems.keySet().iterator();
  while (hmIt.hasNext()) {
    Integer key=(Integer)hmIt.next();
    DisplayItemBean dib=(DisplayItemBean)displayItems.get(key);
    answer.add(dib);
    LOGGER.debug("String_Node_Str" + key + "String_Node_Str"+ dib.getData().getValue());
  }
  LOGGER.debug("String_Node_Str" + displayItems.toString());
  return answer;
}