Program: 115344
Project: 115344
Buggy source:
protected DisplaySectionBean populateNotesWithDBNoteCounts(FormDiscrepancyNotes discNotes,DisplaySectionBean section){
  dndao=new DiscrepancyNoteDAO(sm.getDataSource());
  ArrayList<DiscrepancyNoteBean> ecNotes=dndao.findEventCRFDNotesFromEventCRF(ecb);
  for (int i=0; i < ecNotes.size(); i++) {
    DiscrepancyNoteBean dn=ecNotes.get(i);
    if (INTERVIEWER_NAME.equalsIgnoreCase(dn.getColumn())) {
      discNotes.setNumExistingFieldNotes(INPUT_INTERVIEWER,1);
      request.setAttribute("String_Node_Str","String_Node_Str");
      request.setAttribute(INTERVIEWER_NAME_NOTE,dn);
    }
    if (DATE_INTERVIEWED.equalsIgnoreCase(dn.getColumn())) {
      discNotes.setNumExistingFieldNotes(INPUT_INTERVIEW_DATE,1);
      request.setAttribute("String_Node_Str","String_Node_Str");
      request.setAttribute(INTERVIEWER_DATE_NOTE,dn);
    }
  }
  List<DisplayItemWithGroupBean> allItems=section.getDisplayItemGroups();
  logger.debug("String_Node_Str" + section.getDisplayItemGroups().size());
  this.output(allItems);
  for (int k=0; k < allItems.size(); k++) {
    DisplayItemWithGroupBean itemWithGroup=allItems.get(k);
    if (itemWithGroup.isInGroup()) {
      logger.debug("String_Node_Str");
      List<DisplayItemGroupBean> digbs=itemWithGroup.getItemGroups();
      logger.info("String_Node_Str" + digbs.size());
      for (int i=0; i < digbs.size(); i++) {
        DisplayItemGroupBean displayGroup=digbs.get(i);
        List<DisplayItemBean> items=displayGroup.getItems();
        for (int j=0; j < items.size(); j++) {
          DisplayItemBean dib=items.get(j);
          int itemDataId=dib.getData().getId();
          int numNotes=dndao.findNumExistingNotesForItem(itemDataId);
          int ordinal=this.getManualRows(digbs);
          String inputName=getGroupItemInputName(displayGroup,displayGroup.getFormInputOrdinal(),dib);
          if (!displayGroup.isAuto()) {
            inputName=getGroupItemManualInputName(displayGroup,i,dib);
          }
          discNotes.setNumExistingFieldNotes(inputName,numNotes);
          ArrayList notes=discNotes.getNotes(inputName);
          dib.setNumDiscrepancyNotes(numNotes + notes.size());
          logger.debug("String_Node_Str" + dib.getNumDiscrepancyNotes() + "String_Node_Str"+ dib.getData().getId()+ "String_Node_Str"+ inputName);
          items.set(j,dib);
        }
        displayGroup.setItems(items);
        digbs.set(i,displayGroup);
      }
      itemWithGroup.setItemGroups(digbs);
    }
 else {
      logger.info("String_Node_Str");
      DisplayItemBean dib=itemWithGroup.getSingleItem();
      try {
        ResponseOptionBean rob=(ResponseOptionBean)dib.getMetadata().getResponseSet().getOptions().get(0);
        logger.info("String_Node_Str" + rob.getValue());
      }
 catch (      NullPointerException e) {
      }
      int itemDataId=dib.getData().getId();
      int itemId=dib.getItem().getId();
      int numNotes=dndao.findNumExistingNotesForItem(itemDataId);
      String inputFieldName="String_Node_Str" + itemId;
      discNotes.setNumExistingFieldNotes(inputFieldName,numNotes);
      dib.setNumDiscrepancyNotes(numNotes + discNotes.getNotes(inputFieldName).size());
      ArrayList childItems=dib.getChildren();
      for (int j=0; j < childItems.size(); j++) {
        DisplayItemBean child=(DisplayItemBean)childItems.get(j);
        int childItemDataId=child.getData().getId();
        int childItemId=child.getItem().getId();
        int childNumNotes=dndao.findNumExistingNotesForItem(childItemDataId);
        String childInputFieldName="String_Node_Str" + childItemId;
        logger.debug("String_Node_Str" + childInputFieldName);
        discNotes.setNumExistingFieldNotes(childInputFieldName,childNumNotes);
        child.setNumDiscrepancyNotes(childNumNotes + discNotes.getNotes(childInputFieldName).size());
        childItems.set(j,child);
      }
      dib.setChildren(childItems);
      itemWithGroup.setSingleItem(dib);
    }
    allItems.set(k,itemWithGroup);
  }
  section.setDisplayItemGroups(allItems);
  return section;
}

Fixed version (ground truth):
protected DisplaySectionBean populateNotesWithDBNoteCounts(FormDiscrepancyNotes discNotes,DisplaySectionBean section){
  dndao=new DiscrepancyNoteDAO(sm.getDataSource());
  ArrayList<DiscrepancyNoteBean> ecNotes=dndao.findEventCRFDNotesFromEventCRF(ecb);
  ArrayList<DiscrepancyNoteBean> existingNameNotes=new ArrayList();
  ArrayList<DiscrepancyNoteBean> existingIntrvDateNotes=new ArrayList();
  for (int i=0; i < ecNotes.size(); i++) {
    DiscrepancyNoteBean dn=ecNotes.get(i);
    if (INTERVIEWER_NAME.equalsIgnoreCase(dn.getColumn())) {
      discNotes.setNumExistingFieldNotes(INPUT_INTERVIEWER,1);
      request.setAttribute("String_Node_Str","String_Node_Str");
      request.setAttribute(INTERVIEWER_NAME_NOTE,dn);
      existingNameNotes.add(dn);
    }
    if (DATE_INTERVIEWED.equalsIgnoreCase(dn.getColumn())) {
      discNotes.setNumExistingFieldNotes(INPUT_INTERVIEW_DATE,1);
      request.setAttribute("String_Node_Str","String_Node_Str");
      request.setAttribute(INTERVIEWER_DATE_NOTE,dn);
      existingIntrvDateNotes.add(dn);
    }
  }
  request.setAttribute("String_Node_Str",getDiscrepancyNoteResolutionStatus(existingNameNotes));
  request.setAttribute("String_Node_Str",getDiscrepancyNoteResolutionStatus(existingIntrvDateNotes));
  List<DisplayItemWithGroupBean> allItems=section.getDisplayItemGroups();
  logger.debug("String_Node_Str" + section.getDisplayItemGroups().size());
  this.output(allItems);
  for (int k=0; k < allItems.size(); k++) {
    DisplayItemWithGroupBean itemWithGroup=allItems.get(k);
    if (itemWithGroup.isInGroup()) {
      logger.debug("String_Node_Str");
      List<DisplayItemGroupBean> digbs=itemWithGroup.getItemGroups();
      logger.info("String_Node_Str" + digbs.size());
      for (int i=0; i < digbs.size(); i++) {
        DisplayItemGroupBean displayGroup=digbs.get(i);
        List<DisplayItemBean> items=displayGroup.getItems();
        for (int j=0; j < items.size(); j++) {
          DisplayItemBean dib=items.get(j);
          int itemDataId=dib.getData().getId();
          int numNotes=dndao.findNumExistingNotesForItem(itemDataId);
          int ordinal=this.getManualRows(digbs);
          String inputName=getGroupItemInputName(displayGroup,displayGroup.getFormInputOrdinal(),dib);
          if (!displayGroup.isAuto()) {
            inputName=getGroupItemManualInputName(displayGroup,i,dib);
          }
          discNotes.setNumExistingFieldNotes(inputName,numNotes);
          ArrayList notes=discNotes.getNotes(inputName);
          dib.setNumDiscrepancyNotes(numNotes + notes.size());
          dib.setDiscrepancyNoteStatus(getDiscrepancyNoteResolutionStatus(itemDataId,notes));
          logger.debug("String_Node_Str" + dib.getNumDiscrepancyNotes() + "String_Node_Str"+ dib.getData().getId()+ "String_Node_Str"+ inputName);
          items.set(j,dib);
        }
        displayGroup.setItems(items);
        digbs.set(i,displayGroup);
      }
      itemWithGroup.setItemGroups(digbs);
    }
 else {
      logger.info("String_Node_Str");
      DisplayItemBean dib=itemWithGroup.getSingleItem();
      try {
        ResponseOptionBean rob=(ResponseOptionBean)dib.getMetadata().getResponseSet().getOptions().get(0);
        logger.info("String_Node_Str" + rob.getValue());
      }
 catch (      NullPointerException e) {
      }
      int itemDataId=dib.getData().getId();
      int itemId=dib.getItem().getId();
      int numNotes=dndao.findNumExistingNotesForItem(itemDataId);
      String inputFieldName="String_Node_Str" + itemId;
      discNotes.setNumExistingFieldNotes(inputFieldName,numNotes);
      dib.setNumDiscrepancyNotes(numNotes + discNotes.getNotes(inputFieldName).size());
      dib.setDiscrepancyNoteStatus(getDiscrepancyNoteResolutionStatus(itemDataId,discNotes.getNotes(inputFieldName)));
      ArrayList childItems=dib.getChildren();
      for (int j=0; j < childItems.size(); j++) {
        DisplayItemBean child=(DisplayItemBean)childItems.get(j);
        int childItemDataId=child.getData().getId();
        int childItemId=child.getItem().getId();
        int childNumNotes=dndao.findNumExistingNotesForItem(childItemDataId);
        String childInputFieldName="String_Node_Str" + childItemId;
        logger.debug("String_Node_Str" + childInputFieldName);
        discNotes.setNumExistingFieldNotes(childInputFieldName,childNumNotes);
        child.setNumDiscrepancyNotes(childNumNotes + discNotes.getNotes(childInputFieldName).size());
        child.setDiscrepancyNoteStatus(getDiscrepancyNoteResolutionStatus(childItemDataId,discNotes.getNotes(childInputFieldName)));
        childItems.set(j,child);
      }
      dib.setChildren(childItems);
      itemWithGroup.setSingleItem(dib);
    }
    allItems.set(k,itemWithGroup);
  }
  section.setDisplayItemGroups(allItems);
  return section;
}