Program: 115244
Project: 115244
Buggy source:
protected Element invokeInternal(Element requestElement,Document document) throws Exception {
  System.out.println("String_Node_Str");
  StudyBean studyBean=new StudyBean();
  studyBean.setIdentifier("String_Node_Str");
  try {
    NodeList nlist=requestElement.getElementsByTagNameNS(CONNECTOR_NAMESPACE_V1,"String_Node_Str");
    for (int i=0; i < nlist.getLength(); i++) {
      Node study=nlist.item(i);
      studyBean=studyService.generateStudyBean(getUserAccount(),study);
      StudyBean testStudyBean=getStudyDao().findByUniqueIdentifier(studyBean.getIdentifier());
      boolean updateMe=false;
      int testStudyBeanId=testStudyBean != null ? testStudyBean.getId() : 0;
      ArrayList<StudyBean> sites=studyService.generateSites(getUserAccount(),studyBean,study);
      ArrayList<StudyBean> testSites=new ArrayList<StudyBean>();
      for (      StudyBean site : sites) {
        StudyBean testSite=getStudyDao().findByUniqueIdentifier(site.getIdentifier());
        if ((testSite != null) && (testSite.getParentStudyId() != testStudyBeanId)) {
          throw new CCBusinessFaultException("String_Node_Str" + site.getIdentifier() + "String_Node_Str","String_Node_Str");
        }
 else {
          site.setId(testSite.getId());
          testSites.add(site);
        }
      }
      if (testStudyBean != null) {
        if (!studyBean.getIdentifier().equals(testStudyBean.getIdentifier())) {
          throw new CCBusinessFaultException("String_Node_Str" + studyBean.getIdentifier() + "String_Node_Str","String_Node_Str");
        }
 else {
          updateMe=true;
          studyBean.setUpdater(getUserAccount());
          studyBean.setUpdatedDate(new Date(System.currentTimeMillis()));
          studyBean.setId(testStudyBean.getId());
          sites=testSites;
        }
      }
      StudyConfigService configService=new StudyConfigService(dataSource);
      studyBean=configService.setParametersForStudy(studyBean);
      studyBean.getStudyParameterConfig().setSubjectIdGeneration("String_Node_Str");
      if (!updateMe) {
        studyBean=(StudyBean)getStudyDao().create(studyBean);
      }
 else {
        studyBean=(StudyBean)getStudyDao().update(studyBean);
      }
      studyBean=this.createStudyParameters(studyBean);
      if (!updateMe) {
        for (        StudyBean site : sites) {
          site=configService.setParametersForSite(site);
          site.getStudyParameterConfig().setSubjectIdGeneration("String_Node_Str");
          site.setParentStudyId(studyBean.getId());
          System.out.println("String_Node_Str" + studyBean.getId());
          site=(StudyBean)getStudyDao().create(site);
          site=this.createStudyParameters(site);
        }
      }
 else {
        for (        StudyBean site : sites) {
          site.setStatus(Status.AVAILABLE);
          site.setUpdatedDate(new Date(System.currentTimeMillis()));
          site.setUpdater(getUserAccount());
          site=(StudyBean)getStudyDao().update(site);
        }
      }
    }
    return mapCreateStudyConfirmation(studyBean.getIdentifier());
  }
 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 mapStudyErrorConfirmation("String_Node_Str",ope);
    }
 else {
      System.out.println("String_Node_Str" + npe.getClass().getName());
      return mapStudyErrorConfirmation(npe.getMessage());
    }
  }
}

Fixed version (ground truth):
protected Element invokeInternal(Element requestElement,Document document) throws Exception {
  System.out.println("String_Node_Str");
  StudyBean studyBean=new StudyBean();
  studyBean.setIdentifier("String_Node_Str");
  try {
    NodeList nlist=requestElement.getElementsByTagNameNS(CONNECTOR_NAMESPACE_V1,"String_Node_Str");
    for (int i=0; i < nlist.getLength(); i++) {
      Node study=nlist.item(i);
      studyBean=studyService.generateStudyBean(getUserAccount(),study);
      StudyBean testStudyBean=getStudyDao().findByUniqueIdentifier(studyBean.getIdentifier());
      boolean updateMe=false;
      int testStudyBeanId=testStudyBean != null ? testStudyBean.getId() : 0;
      ArrayList<StudyBean> sites=studyService.generateSites(getUserAccount(),studyBean,study);
      ArrayList<StudyBean> testSites=new ArrayList<StudyBean>();
      for (      StudyBean site : sites) {
        StudyBean testSite=getStudyDao().findByUniqueIdentifier(site.getIdentifier());
        if ((testSite != null) && (testSite.getParentStudyId() != testStudyBeanId)) {
          throw new CCBusinessFaultException("String_Node_Str" + site.getIdentifier() + "String_Node_Str","String_Node_Str");
        }
 else         if (testSite != null) {
          site.setId(testSite.getId());
          testSites.add(site);
        }
      }
      if (testStudyBean != null) {
        if (!studyBean.getIdentifier().equals(testStudyBean.getIdentifier())) {
          throw new CCBusinessFaultException("String_Node_Str" + studyBean.getIdentifier() + "String_Node_Str","String_Node_Str");
        }
 else {
          updateMe=true;
          studyBean.setUpdater(getUserAccount());
          studyBean.setUpdatedDate(new Date(System.currentTimeMillis()));
          studyBean.setId(testStudyBean.getId());
          sites=testSites;
        }
      }
      StudyConfigService configService=new StudyConfigService(dataSource);
      studyBean=configService.setParametersForStudy(studyBean);
      studyBean.getStudyParameterConfig().setSubjectIdGeneration("String_Node_Str");
      if (!updateMe) {
        studyBean=(StudyBean)getStudyDao().create(studyBean);
      }
 else {
        studyBean.setOldStatus(Status.DELETED);
        studyBean=(StudyBean)getStudyDao().update(studyBean);
      }
      studyBean=this.createStudyParameters(studyBean);
      if (!updateMe) {
        for (        StudyBean site : sites) {
          site=configService.setParametersForSite(site);
          site.getStudyParameterConfig().setSubjectIdGeneration("String_Node_Str");
          site.setParentStudyId(studyBean.getId());
          site.setParentStudyName(studyBean.getName());
          System.out.println("String_Node_Str" + studyBean.getId());
          site=(StudyBean)getStudyDao().create(site);
          site=this.createStudyParameters(site);
        }
      }
 else {
        for (        StudyBean site : sites) {
          site.setStatus(Status.AVAILABLE);
          site.setOldStatus(Status.DELETED);
          site.setParentStudyId(studyBean.getId());
          site.setParentStudyName(studyBean.getName());
          site.setUpdatedDate(new Date(System.currentTimeMillis()));
          site.setUpdater(getUserAccount());
          site=(StudyBean)getStudyDao().update(site);
        }
      }
    }
    return mapCreateStudyConfirmation(studyBean.getIdentifier());
  }
 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 mapStudyErrorConfirmation("String_Node_Str",ope);
    }
 else {
      System.out.println("String_Node_Str" + npe.getClass().getName());
      return mapStudyErrorConfirmation(npe.getMessage());
    }
  }
}