Program: 84508
Project: 84508
Buggy source:
/** 
 * The onSubmit function receives the form/command object that was modified by the input form and saves it to the db
 * @see org.springframework.web.servlet.mvc.SimpleFormController#onSubmit(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse,java.lang.Object,org.springframework.validation.BindException)
 */
protected ModelAndView onSubmit(HttpServletRequest request,HttpServletResponse response,Object obj,BindException errors) throws Exception {
  HttpSession httpSession=request.getSession();
  Patient patient=(Patient)obj;
  if (Context.isAuthenticated()) {
    MessageSourceAccessor msa=getMessageSourceAccessor();
    String action=request.getParameter("String_Node_Str");
    PatientService ps=Context.getPatientService();
    if (action.equals(msa.getMessage("String_Node_Str"))) {
      try {
        ps.purgePatient(patient);
        httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR,"String_Node_Str");
        return new ModelAndView(new RedirectView("String_Node_Str"));
      }
 catch (      APIException e) {
        log.error(e);
        httpSession.setAttribute(WebConstants.OPENMRS_ERROR_ATTR,"String_Node_Str");
        return new ModelAndView(new RedirectView(getSuccessView() + "String_Node_Str" + patient.getPatientId().toString()));
      }
    }
 else {
      boolean isError=false;
      try {
        Context.getPatientService().savePatient(patient);
      }
 catch (      InvalidIdentifierFormatException iife) {
        log.error(iife);
        patient.removeIdentifier(iife.getPatientIdentifier());
        httpSession.setAttribute(WebConstants.OPENMRS_ERROR_ATTR,"String_Node_Str");
        isError=true;
      }
catch (      IdentifierNotUniqueException inue) {
        log.error(inue);
        patient.removeIdentifier(inue.getPatientIdentifier());
        httpSession.setAttribute(WebConstants.OPENMRS_ERROR_ATTR,"String_Node_Str");
        isError=true;
      }
catch (      DuplicateIdentifierException die) {
        log.error(die);
        patient.removeIdentifier(die.getPatientIdentifier());
        httpSession.setAttribute(WebConstants.OPENMRS_ERROR_ATTR,"String_Node_Str");
        isError=true;
      }
catch (      InsufficientIdentifiersException iie) {
        log.error(iie);
        patient.removeIdentifier(iie.getPatientIdentifier());
        httpSession.setAttribute(WebConstants.OPENMRS_ERROR_ATTR,"String_Node_Str");
        isError=true;
      }
catch (      PatientIdentifierException pie) {
        log.error(pie);
        patient.removeIdentifier(pie.getPatientIdentifier());
        httpSession.setAttribute(WebConstants.OPENMRS_ERROR_ATTR,"String_Node_Str");
        isError=true;
      }
      if (patient.getDead() && !isError) {
        log.debug("String_Node_Str");
        String causeOfDeathConceptId=Context.getAdministrationService().getGlobalProperty("String_Node_Str");
        Concept causeOfDeath=Context.getConceptService().getConcept(causeOfDeathConceptId);
        if (causeOfDeath != null) {
          List<Obs> obssDeath=Context.getObsService().getObservationsByPersonAndConcept(patient,causeOfDeath);
          if (obssDeath != null) {
            if (obssDeath.size() > 1) {
              log.error("String_Node_Str" + obssDeath.size() + "String_Node_Str");
            }
 else {
              Obs obsDeath=null;
              if (obssDeath.size() == 1) {
                log.debug("String_Node_Str");
                obsDeath=obssDeath.iterator().next();
              }
 else {
                log.debug("String_Node_Str");
                obsDeath=new Obs();
                obsDeath.setPerson(patient);
                obsDeath.setConcept(causeOfDeath);
                Location location=Context.getLocationService().getDefaultLocation();
                if (location != null)                 obsDeath.setLocation(location);
 else                 log.error("String_Node_Str");
              }
              Concept currCause=patient.getCauseOfDeath();
              if (currCause == null) {
                log.debug("String_Node_Str");
                String noneConcept=Context.getAdministrationService().getGlobalProperty("String_Node_Str");
                currCause=Context.getConceptService().getConcept(noneConcept);
              }
              if (currCause != null) {
                log.debug("String_Node_Str");
                obsDeath.setValueCoded(currCause);
                obsDeath.setValueCodedName(currCause.getName());
                Date dateDeath=patient.getDeathDate();
                if (dateDeath == null)                 dateDeath=new Date();
                obsDeath.setObsDatetime(dateDeath);
                String otherConcept=Context.getAdministrationService().getGlobalProperty("String_Node_Str");
                Concept conceptOther=Context.getConceptService().getConcept(otherConcept);
                if (conceptOther != null) {
                  if (conceptOther.equals(currCause)) {
                    String otherInfo=ServletRequestUtils.getStringParameter(request,"String_Node_Str","String_Node_Str");
                    log.debug("String_Node_Str" + otherInfo);
                    obsDeath.setValueText(otherInfo);
                  }
 else {
                    log.debug("String_Node_Str");
                    obsDeath.setValueText("String_Node_Str");
                  }
                }
 else {
                  log.debug("String_Node_Str");
                  obsDeath.setValueText("String_Node_Str");
                }
                Context.getObsService().saveObs(obsDeath,obsDeath.getVoidReason());
              }
 else {
                log.debug("String_Node_Str");
              }
            }
          }
        }
 else {
          log.debug("String_Node_Str");
        }
      }
      if (!isError) {
        String view=getSuccessView();
        httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR,"String_Node_Str");
        view=view + "String_Node_Str" + patient.getPatientId();
        return new ModelAndView(new RedirectView(view));
      }
 else {
        return showForm(request,response,errors);
      }
    }
  }
  return new ModelAndView(new RedirectView(getFormView()));
}

Fixed version (ground truth):
/** 
 * The onSubmit function receives the form/command object that was modified by the input form and saves it to the db
 * @see org.springframework.web.servlet.mvc.SimpleFormController#onSubmit(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse,java.lang.Object,org.springframework.validation.BindException)
 */
protected ModelAndView onSubmit(HttpServletRequest request,HttpServletResponse response,Object obj,BindException errors) throws Exception {
  HttpSession httpSession=request.getSession();
  Patient patient=(Patient)obj;
  if (Context.isAuthenticated()) {
    MessageSourceAccessor msa=getMessageSourceAccessor();
    String action=request.getParameter("String_Node_Str");
    PatientService ps=Context.getPatientService();
    if (action.equals(msa.getMessage("String_Node_Str"))) {
      try {
        ps.purgePatient(patient);
        httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR,"String_Node_Str");
        return new ModelAndView(new RedirectView("String_Node_Str"));
      }
 catch (      APIException e) {
        log.error(e);
        httpSession.setAttribute(WebConstants.OPENMRS_ERROR_ATTR,"String_Node_Str");
        return new ModelAndView(new RedirectView(getSuccessView() + "String_Node_Str" + patient.getPatientId().toString()));
      }
    }
 else {
      boolean isError=false;
      try {
        Context.getPatientService().savePatient(patient);
      }
 catch (      InvalidIdentifierFormatException iife) {
        log.error(iife);
        patient.removeIdentifier(iife.getPatientIdentifier());
        httpSession.setAttribute(WebConstants.OPENMRS_ERROR_ATTR,"String_Node_Str");
        isError=true;
      }
catch (      IdentifierNotUniqueException inue) {
        log.error(inue);
        patient.removeIdentifier(inue.getPatientIdentifier());
        httpSession.setAttribute(WebConstants.OPENMRS_ERROR_ATTR,"String_Node_Str");
        isError=true;
      }
catch (      DuplicateIdentifierException die) {
        log.error(die);
        patient.removeIdentifier(die.getPatientIdentifier());
        httpSession.setAttribute(WebConstants.OPENMRS_ERROR_ATTR,"String_Node_Str");
        isError=true;
      }
catch (      InsufficientIdentifiersException iie) {
        log.error(iie);
        patient.removeIdentifier(iie.getPatientIdentifier());
        httpSession.setAttribute(WebConstants.OPENMRS_ERROR_ATTR,"String_Node_Str");
        isError=true;
      }
catch (      PatientIdentifierException pie) {
        log.error(pie);
        patient.removeIdentifier(pie.getPatientIdentifier());
        httpSession.setAttribute(WebConstants.OPENMRS_ERROR_ATTR,"String_Node_Str");
        isError=true;
      }
      if (patient.getDead() && !isError) {
        log.debug("String_Node_Str");
        String causeOfDeathConceptId=Context.getAdministrationService().getGlobalProperty("String_Node_Str");
        Concept causeOfDeath=Context.getConceptService().getConcept(causeOfDeathConceptId);
        if (causeOfDeath != null) {
          List<Obs> obssDeath=Context.getObsService().getObservationsByPersonAndConcept(patient,causeOfDeath);
          if (obssDeath != null) {
            if (obssDeath.size() > 1) {
              log.error("String_Node_Str" + obssDeath.size() + "String_Node_Str");
            }
 else {
              Obs obsDeath=null;
              if (obssDeath.size() == 1) {
                log.debug("String_Node_Str");
                obsDeath=obssDeath.iterator().next();
              }
 else {
                log.debug("String_Node_Str");
                obsDeath=new Obs();
                obsDeath.setPerson(patient);
                obsDeath.setConcept(causeOfDeath);
                Location location=Context.getLocationService().getDefaultLocation();
                if (location != null)                 obsDeath.setLocation(location);
 else                 log.error("String_Node_Str");
              }
              Concept currCause=patient.getCauseOfDeath();
              if (currCause == null) {
                log.debug("String_Node_Str");
                String noneConcept=Context.getAdministrationService().getGlobalProperty("String_Node_Str");
                currCause=Context.getConceptService().getConcept(noneConcept);
              }
              if (currCause != null) {
                log.debug("String_Node_Str");
                obsDeath.setValueCoded(currCause);
                obsDeath.setValueCodedName(currCause.getName());
                Date dateDeath=patient.getDeathDate();
                if (dateDeath == null)                 dateDeath=new Date();
                obsDeath.setObsDatetime(dateDeath);
                String otherConcept=Context.getAdministrationService().getGlobalProperty("String_Node_Str");
                Concept conceptOther=Context.getConceptService().getConcept(otherConcept);
                boolean deathReasonChanged=false;
                if (conceptOther != null) {
                  String otherInfo=ServletRequestUtils.getStringParameter(request,"String_Node_Str","String_Node_Str");
                  if (conceptOther.equals(currCause)) {
                    deathReasonChanged=!otherInfo.equals(obsDeath.getValueText());
                    log.debug("String_Node_Str" + otherInfo);
                    obsDeath.setValueText(otherInfo);
                  }
 else {
                    deathReasonChanged=!otherInfo.equals("String_Node_Str");
                    log.debug("String_Node_Str");
                    obsDeath.setValueText("String_Node_Str");
                  }
                }
 else {
                  log.debug("String_Node_Str");
                  obsDeath.setValueText("String_Node_Str");
                }
                boolean shouldSaveObs=(null == obsDeath.getId()) || deathReasonChanged;
                if (shouldSaveObs) {
                  if (null == obsDeath.getVoidReason())                   obsDeath.setVoidReason("String_Node_Str");
                  Context.getObsService().saveObs(obsDeath,obsDeath.getVoidReason());
                }
              }
 else {
                log.debug("String_Node_Str");
              }
            }
          }
        }
 else {
          log.debug("String_Node_Str");
        }
      }
      if (!isError) {
        String view=getSuccessView();
        httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR,"String_Node_Str");
        view=view + "String_Node_Str" + patient.getPatientId();
        return new ModelAndView(new RedirectView(view));
      }
 else {
        return showForm(request,response,errors);
      }
    }
  }
  return new ModelAndView(new RedirectView(getFormView()));
}