Program: 147049
Project: 147049
Buggy source:
private void processCaseReferral(TreeElement referral,Case c,Date date) throws MalformedCaseModelException {
  Vector referralIds=referral.getChildrenWithName("String_Node_Str");
  if (referralIds.size() < 1) {
    throw new MalformedCaseModelException("String_Node_Str","String_Node_Str");
  }
  String referralId=(String)serializer.serializeAnswerData(((TreeElement)referralIds.elementAt(0)).getValue());
  Date followup=DateUtils.dateAdd(date,3);
  Vector followupDates=referral.getChildrenWithName("String_Node_Str");
  if (followupDates.size() >= 1 && ((TreeElement)followupDates.elementAt(0)).isRelevant()) {
    followup=(Date)(((TreeElement)followupDates.elementAt(0))).getValue().getValue();
  }
  Vector childElements=referral.getChildren();
  for (int i=0; i < childElements.size(); ++i) {
    TreeElement kid=(TreeElement)childElements.elementAt(i);
    if (kid.getName().equals("String_Node_Str")) {
      Vector types=kid.getChildrenWithName("String_Node_Str");
      if (types.size() < 1) {
        throw new MalformedCaseModelException("String_Node_Str","String_Node_Str");
      }
      String typeString=(String)serializer.serializeAnswerData(((TreeElement)types.elementAt(0)).getValue());
      Vector referralTypeList=DateUtils.split(typeString,"String_Node_Str",false);
      for (int ir=0; ir < referralTypeList.size(); ++ir) {
        String referralType=(String)referralTypeList.elementAt(ir);
        PatientReferral r=new PatientReferral(referralType,date,referralId,c.getCaseId(),followup);
        commit(r);
      }
    }
 else     if (kid.getName().equals("String_Node_Str")) {
      Vector types=kid.getChildrenWithName("String_Node_Str");
      if (types.size() < 1) {
        throw new MalformedCaseModelException("String_Node_Str","String_Node_Str");
      }
      String refType=(String)serializer.serializeAnswerData((((TreeElement)types.elementAt(0)).getValue()));
      PatientReferral r=getReferral(referralId,refType);
      r.setDateDue(followup);
      Vector dateCloseds=kid.getChildrenWithName("String_Node_Str");
      if (dateCloseds.size() > 0) {
        r.close();
      }
      commit(r);
    }
  }
}

Fixed version (ground truth):
private void processCaseReferral(TreeElement referral,Case c,Date date) throws MalformedCaseModelException {
  Vector referralIds=referral.getChildrenWithName("String_Node_Str");
  if (referralIds.size() < 1) {
    throw new MalformedCaseModelException("String_Node_Str","String_Node_Str");
  }
  String referralId=(String)serializer.serializeAnswerData(((TreeElement)referralIds.elementAt(0)).getValue());
  Date followup=DateUtils.dateAdd(date,3);
  Vector followupDates=referral.getChildrenWithName("String_Node_Str");
  if (followupDates.size() >= 1 && ((TreeElement)followupDates.elementAt(0)).isRelevant()) {
    followup=(Date)(((TreeElement)followupDates.elementAt(0))).getValue().getValue();
  }
  Vector childElements=referral.getChildren();
  for (int i=0; i < childElements.size(); ++i) {
    TreeElement kid=(TreeElement)childElements.elementAt(i);
    if (kid.getName().equals("String_Node_Str")) {
      Vector types=kid.getChildrenWithName("String_Node_Str");
      if (types.size() < 1) {
        throw new MalformedCaseModelException("String_Node_Str","String_Node_Str");
      }
      String typeString=(String)serializer.serializeAnswerData(((TreeElement)types.elementAt(0)).getValue());
      Vector referralTypeList=DateUtils.split(typeString,"String_Node_Str",false);
      for (int ir=0; ir < referralTypeList.size(); ++ir) {
        String referralType=(String)referralTypeList.elementAt(ir);
        PatientReferral r=new PatientReferral(referralType,date,referralId,c.getCaseId(),followup);
        commit(r);
      }
    }
 else     if (kid.getName().equals("String_Node_Str")) {
      Vector types=kid.getChildrenWithName("String_Node_Str");
      if (types.size() < 1) {
        throw new MalformedCaseModelException("String_Node_Str","String_Node_Str");
      }
      String refType=(String)serializer.serializeAnswerData((((TreeElement)types.elementAt(0)).getValue()));
      PatientReferral r=getReferral(referralId,refType);
      r.setDateDue(followup);
      Vector dateCloseds=kid.getChildrenWithName("String_Node_Str");
      if (dateCloseds.size() > 0 && ((TreeElement)dateCloseds.elementAt(0)).isRelevant()) {
        r.close();
      }
      commit(r);
    }
  }
}