Program: 115225
Project: 115225
Buggy source:
protected Element invokeInternal(Element requestElement,Document document) throws Exception {
  SubjectBean finalSubjectBean=new SubjectBean();
  StudySubjectBean studySubjectBean=new StudySubjectBean();
  finalSubjectBean.setUniqueIdentifier("String_Node_Str");
  NodeList subjects=requestElement.getElementsByTagNameNS(CONNECTOR_NAMESPACE_V1,"String_Node_Str");
  try {
    if (subjects.getLength() > 0) {
      System.out.println("String_Node_Str" + subjects.getLength());
      for (int i=0; i < subjects.getLength(); i++) {
        Node childNode=subjects.item(i);
        UserAccountBean user=this.getUserAccount();
        Role r=user.getActiveStudyRole();
        if (r != null && (r.equals(Role.COORDINATOR) || r.equals(Role.STUDYDIRECTOR) || r.equals(Role.INVESTIGATOR)|| r.equals(Role.RESEARCHASSISTANT)|| r.equals(Role.ADMIN))) {
        }
 else {
          throw new CCSystemFaultException("String_Node_Str");
        }
        RegisterSubjectBean subjectBean=subjectService.generateSubjectBean(user,childNode,getStudyDao(),getStudyParamValueDao());
        NodeList performedMilestones=requestElement.getElementsByTagNameNS(CONNECTOR_NAMESPACE_V1,"String_Node_Str");
        if (performedMilestones.getLength() > 0) {
          for (int j=0; j < performedMilestones.getLength(); j++) {
            Node milestone=performedMilestones.item(j);
            subjectBean=subjectService.attachStudyIdentifiers(subjectBean,milestone);
            int nextLabel=getStudySubjectDao().findTheGreatestLabel() + 1;
            subjectBean.setStudySubjectLabel(new Integer(nextLabel).toString());
          }
        }
        finalSubjectBean=subjectService.generateSubjectBean(subjectBean);
        SubjectBean testSubjectBean=getSubjectDao().findByUniqueIdentifier(subjectBean.getUniqueIdentifier());
        boolean updateMe=false;
        if (testSubjectBean.getId() > 0) {
          if (subjectService.isSubjectIdentical(subjectBean,testSubjectBean)) {
            testSubjectBean.setUpdater(user);
            if (finalSubjectBean.getDateOfBirth() != null) {
              testSubjectBean.setDobCollected(true);
              testSubjectBean.setDateOfBirth(finalSubjectBean.getDateOfBirth());
            }
            testSubjectBean.setStatus(Status.AVAILABLE);
            updateMe=true;
            finalSubjectBean=testSubjectBean;
          }
 else {
            throw new CCBusinessFaultException("String_Node_Str" + subjectBean.getUniqueIdentifier() + "String_Node_Str");
          }
        }
        studySubjectBean=subjectService.generateStudySubjectBean(subjectBean,finalSubjectBean,subjectBean.getStudyBean());
        StudySubjectBean testStudySubjectBean=getStudySubjectDao().findByLabelAndStudy(subjectBean.getStudySubjectLabel(),subjectBean.getStudyBean());
        if (updateMe) {
          testStudySubjectBean=getStudySubjectDao().findBySubjectIdAndStudy(finalSubjectBean.getId(),subjectBean.getStudyBean());
          subjectBean.setStudySubjectLabel(testStudySubjectBean.getLabel());
          System.out.println("String_Node_Str" + testStudySubjectBean.getLabel());
        }
        boolean updateStudySubject=false;
        if (testStudySubjectBean.getId() > 0) {
          if (subjectService.isStudySubjectIdentical(subjectBean,finalSubjectBean,testStudySubjectBean,subjectBean.getStudyBean())) {
            testStudySubjectBean.setUpdater(user);
            testStudySubjectBean.setStatus(Status.AVAILABLE);
            updateStudySubject=true;
            studySubjectBean=testStudySubjectBean;
          }
 else {
            throw new CCBusinessFaultException("String_Node_Str" + subjectBean.getStudySubjectLabel() + "String_Node_Str");
          }
        }
        if (updateMe) {
          finalSubjectBean=(SubjectBean)getSubjectDao().update(finalSubjectBean);
        }
 else {
          finalSubjectBean=getSubjectDao().create(finalSubjectBean);
        }
        studySubjectBean.setSubjectId(finalSubjectBean.getId());
        if (updateStudySubject) {
          studySubjectBean=(StudySubjectBean)getStudySubjectDao().update(studySubjectBean);
          System.out.println("String_Node_Str");
        }
 else {
          studySubjectBean=getStudySubjectDao().create(studySubjectBean,false);
        }
        System.out.println("String_Node_Str");
      }
    }
    return mapRegisterSubjectConfirmation(studySubjectBean.getLabel());
  }
 catch (  Exception npe) {
    npe.printStackTrace();
    if (npe.getClass().getName().startsWith("String_Node_Str")) {
      System.out.println("String_Node_Str" + npe.getClass().getName());
      OpenClinicaException ope=(OpenClinicaException)npe;
      return mapSubjectErrorConfirmation("String_Node_Str",ope);
    }
 else {
      System.out.println("String_Node_Str" + npe.getClass().getName());
      return mapSubjectErrorConfirmation(npe.getMessage());
    }
  }
}

Fixed version (ground truth):
protected Element invokeInternal(Element requestElement,Document document) throws Exception {
  SubjectBean finalSubjectBean=new SubjectBean();
  StudySubjectBean studySubjectBean=new StudySubjectBean();
  finalSubjectBean.setUniqueIdentifier("String_Node_Str");
  NodeList subjects=requestElement.getElementsByTagNameNS(CONNECTOR_NAMESPACE_V1,"String_Node_Str");
  try {
    if (subjects.getLength() > 0) {
      System.out.println("String_Node_Str" + subjects.getLength());
      for (int i=0; i < subjects.getLength(); i++) {
        Node childNode=subjects.item(i);
        UserAccountBean user=this.getUserAccount();
        Role r=user.getActiveStudyRole();
        if (r != null && (r.equals(Role.COORDINATOR) || r.equals(Role.STUDYDIRECTOR) || r.equals(Role.INVESTIGATOR)|| r.equals(Role.RESEARCHASSISTANT)|| r.equals(Role.ADMIN))) {
        }
 else {
          throw new CCSystemFaultException("String_Node_Str");
        }
        RegisterSubjectBean subjectBean=subjectService.generateSubjectBean(user,childNode,getStudyDao(),getStudyParamValueDao());
        NodeList performedMilestones=requestElement.getElementsByTagNameNS(CONNECTOR_NAMESPACE_V1,"String_Node_Str");
        if (performedMilestones.getLength() > 0) {
          for (int j=0; j < performedMilestones.getLength(); j++) {
            Node milestone=performedMilestones.item(j);
            subjectBean=subjectService.attachStudyIdentifiers(subjectBean,milestone);
            int nextLabel=getStudySubjectDao().findTheGreatestLabel() + 1;
            subjectBean.setStudySubjectLabel(new Integer(nextLabel).toString());
          }
        }
        finalSubjectBean=subjectService.generateSubjectBean(subjectBean);
        SubjectBean testSubjectBean=getSubjectDao().findByUniqueIdentifier(subjectBean.getUniqueIdentifier());
        boolean updateMe=false;
        if (testSubjectBean.getId() > 0) {
          if (subjectService.isSubjectIdentical(subjectBean,testSubjectBean)) {
            testSubjectBean.setUpdater(user);
            if (finalSubjectBean.getDateOfBirth() != null) {
              testSubjectBean.setDobCollected(true);
              testSubjectBean.setDateOfBirth(finalSubjectBean.getDateOfBirth());
            }
            testSubjectBean.setStatus(Status.AVAILABLE);
            updateMe=true;
            finalSubjectBean=testSubjectBean;
          }
 else {
            throw new CCBusinessFaultException("String_Node_Str" + subjectBean.getUniqueIdentifier() + "String_Node_Str");
          }
        }
        studySubjectBean=subjectService.generateStudySubjectBean(subjectBean,finalSubjectBean,subjectBean.getStudyBean());
        StudySubjectBean testStudySubjectBean=getStudySubjectDao().findByLabelAndStudy(subjectBean.getStudySubjectLabel(),subjectBean.getStudyBean());
        if (updateMe) {
          testStudySubjectBean=getStudySubjectDao().findBySubjectIdAndStudy(finalSubjectBean.getId(),subjectBean.getStudyBean());
          subjectBean.setStudySubjectLabel(testStudySubjectBean.getLabel());
          System.out.println("String_Node_Str" + testStudySubjectBean.getLabel());
        }
        boolean updateStudySubject=false;
        if (testStudySubjectBean.getId() > 0) {
          if (subjectService.isStudySubjectIdentical(subjectBean,finalSubjectBean,testStudySubjectBean,subjectBean.getStudyBean())) {
            testStudySubjectBean.setUpdater(user);
            testStudySubjectBean.setStatus(Status.AVAILABLE);
            updateStudySubject=true;
            studySubjectBean=testStudySubjectBean;
          }
 else {
            throw new CCBusinessFaultException("String_Node_Str" + subjectBean.getStudySubjectLabel() + "String_Node_Str");
          }
        }
        if (updateMe) {
          finalSubjectBean=(SubjectBean)getSubjectDao().update(finalSubjectBean);
          finalSubjectBean=subjectService.changeStatus(Status.AUTO_DELETED,Status.AVAILABLE,finalSubjectBean,user,getSubjectDao(),getStudySubjectDao(),getEventCrfDao(),getItemDataDao(),getStudyEventDao());
        }
 else {
          finalSubjectBean=getSubjectDao().create(finalSubjectBean);
        }
        studySubjectBean.setSubjectId(finalSubjectBean.getId());
        if (updateStudySubject) {
          studySubjectBean=(StudySubjectBean)getStudySubjectDao().update(studySubjectBean);
          System.out.println("String_Node_Str");
        }
 else {
          studySubjectBean=getStudySubjectDao().create(studySubjectBean,false);
        }
        System.out.println("String_Node_Str");
      }
    }
    return mapRegisterSubjectConfirmation(studySubjectBean.getLabel());
  }
 catch (  Exception npe) {
    npe.printStackTrace();
    if (npe.getClass().getName().startsWith("String_Node_Str")) {
      System.out.println("String_Node_Str" + npe.getClass().getName());
      OpenClinicaException ope=(OpenClinicaException)npe;
      return mapSubjectErrorConfirmation("String_Node_Str",ope);
    }
 else {
      System.out.println("String_Node_Str" + npe.getClass().getName());
      return mapSubjectErrorConfirmation(npe.getMessage());
    }
  }
}