Program: 189332
Project: 189332
Buggy source:
/** 
 * Load randomly generated submissions.
 */
public static void loadSubmissions(long seed,int howMany) throws IOException {
  List<EmbargoType> embargos=settingRepo.findAllEmbargoTypes();
  Person reviewer=personRepo.findPersonByEmail("String_Node_Str");
  Random random=new Random(seed);
  long start=System.currentTimeMillis();
  for (int i=0; i < howMany; i++) {
    context.turnOffAuthorization();
    Person student=personRepo.findPersonByNetId("String_Node_Str" + i);
    if (student == null) {
      String[] studentName=generateRandomName(random,ACTOR_NAMES);
      String studentEmail=generateRandomEmail(random,studentName);
      studentEmail=studentEmail.replaceFirst("String_Node_Str",(i + 1) + "String_Node_Str");
      student=personRepo.createPerson("String_Node_Str" + i,studentEmail,studentName[0],studentName[1],RoleType.STUDENT).save();
      if (i > 0) {
        student.setMiddleName(studentName[2]);
        student.setPassword("String_Node_Str");
        student.setCurrentPhoneNumber("String_Node_Str");
        student.setCurrentPostalAddress("String_Node_Str");
        student.setPermanentPhoneNumber("String_Node_Str");
        student.setPermanentPostalAddress("String_Node_Str");
        student.setPermanentEmailAddress("String_Node_Str");
        student.setInstitutionalIdentifier("String_Node_Str" + random.nextInt(9) + random.nextInt(9)+ random.nextInt(9)+ random.nextInt(9)+ random.nextInt(9)+ random.nextInt(9)+ random.nextInt(9)+ random.nextInt(9)+ random.nextInt(9));
        if (random.nextInt(100) > 50)         student.setOrcid("String_Node_Str" + random.nextInt(9) + random.nextInt(9)+ random.nextInt(9)+ random.nextInt(9)+ "String_Node_Str"+ random.nextInt(9)+ random.nextInt(9)+ random.nextInt(9)+ random.nextInt(9)+ "String_Node_Str"+ random.nextInt(9)+ random.nextInt(9)+ random.nextInt(9)+ random.nextInt(9)+ "String_Node_Str"+ random.nextInt(9)+ random.nextInt(9)+ random.nextInt(9)+ random.nextInt(9));
      }
      student.save();
    }
    String[] studentName=new String[3];
    studentName[0]=student.getFirstName();
    studentName[1]=student.getLastName();
    studentName[2]=student.getMiddleName();
    context.restoreAuthorization();
    context.login(student);
    Submission sub=subRepo.createSubmission(student).save();
    if (i > 0) {
      sub.setStudentFirstName(studentName[0]);
      sub.setStudentLastName(studentName[1]);
      sub.setStudentMiddleName(studentName[2]);
      if (random.nextInt(100) > 30)       sub.setStudentBirthYear(random.nextInt(20) + 1980);
      if (student.getOrcid() != null)       sub.setOrcid(student.getOrcid());
      if (random.nextInt(100) > 5)       sub.addEmbargoType(embargos.get(random.nextInt(embargos.size() - 1)));
      int members=random.nextInt(5);
      String[] firstMemberName=null;
      for (int m=0; m < members; m++) {
        String[] memberName=generateRandomName(random,FAMOUS_NAMES);
        if (firstMemberName == null)         firstMemberName=memberName;
        CommitteeMember member=sub.addCommitteeMember(memberName[0],memberName[1],memberName[2]).save();
        if (random.nextInt(100) > 75) {
          DegreeLevelArray role=ROLETYPES_DEFINITIONS[random.nextInt(ROLETYPES_DEFINITIONS.length - 1)];
          member.addRole(role.name);
          if (random.nextInt(100) > 75) {
            role=ROLETYPES_DEFINITIONS[random.nextInt(ROLETYPES_DEFINITIONS.length - 1)];
            try {
              member.addRole(role.name);
            }
 catch (            IllegalArgumentException iae) {
            }
            ;
          }
        }
        member.save();
      }
      if (random.nextInt(100) > 5 && firstMemberName != null)       sub.setCommitteeContactEmail(generateRandomEmail(random,firstMemberName));
      if (random.nextInt(100) > 5) {
        DegreeLevelArray degree=DEGREES_DEFINITIONS[random.nextInt(DEGREES_DEFINITIONS.length - 1)];
        sub.setDegree(degree.name);
        sub.setDegreeLevel(degree.degreeLevel);
      }
      if (random.nextInt(100) > 5)       sub.setDocumentTitle(generateRandomTitle(random));
      if (random.nextInt(100) > 5)       sub.setDocumentAbstract(generateRandomAbstract(random));
      if (random.nextInt(100) > 5)       sub.setDocumentKeywords(generateRandomKeywords(random));
      if (random.nextInt(100) > 5) {
        List<ProquestSubject> subjects=proquestRepo.findAllSubjects();
        sub.addDocumentSubject(subjects.get(random.nextInt(subjects.size() - 1)).getDescription());
        if (random.nextInt(100) > 5) {
          sub.addDocumentSubject(subjects.get(random.nextInt(subjects.size() - 1)).getDescription());
          if (random.nextInt(100) > 5) {
            sub.addDocumentSubject(subjects.get(random.nextInt(subjects.size() - 1)).getDescription());
          }
        }
      }
      if (random.nextInt(100) > 5) {
        sub.setDocumentLanguage(LANGUAGES_DEFINITIONS[random.nextInt(LANGUAGES_DEFINITIONS.length)]);
      }
      if (random.nextInt(100) > 5)       sub.setDepartment(DEPARTMENTS_DEFINITIONS[random.nextInt(DEPARTMENTS_DEFINITIONS.length - 1)].name);
      if (random.nextInt(100) > 5)       sub.setProgram(PROGRAMS_DEFINITIONS[random.nextInt(PROGRAMS_DEFINITIONS.length - 1)].name);
      if (random.nextInt(100) > 5)       sub.setCollege(COLLEGES_DEFINITIONS[random.nextInt(COLLEGES_DEFINITIONS.length - 1)].name);
      if (random.nextInt(100) > 5)       sub.setMajor(MAJORS_DEFINITIONS[random.nextInt(MAJORS_DEFINITIONS.length - 1)]);
      if (random.nextInt(100) > 5)       sub.setDocumentType(DOCTYPES_DEFINITIONS[random.nextInt(DOCTYPES_DEFINITIONS.length - 1)].name);
      if (random.nextInt(100) > 5) {
        sub.setGraduationYear(random.nextInt(10) + 2002);
        sub.setGraduationMonth(GRAD_MONTHS_DEFINITIONS[random.nextInt(GRAD_MONTHS_DEFINITIONS.length - 1)]);
      }
      if (random.nextInt(100) > 50)       sub.setDefenseDate(generateRandomDate(random,2,2010));
      if (random.nextInt(100) > 5)       sub.setUMIRelease(random.nextBoolean());
      if (random.nextInt(100) > 5)       sub.setSubmissionDate(generateRandomDate(random,2,2010));
      if (random.nextInt(100) > 70)       sub.setApprovalDate(generateRandomDate(random,2,2010));
      if (random.nextInt(100) > 50)       sub.setCommitteeEmbargoApprovalDate(generateRandomDate(random,2,2010));
      if (random.nextInt(100) > 50)       sub.setCommitteeApprovalDate(generateRandomDate(random,2,2010));
      if (random.nextInt(100) > 5)       sub.setCommitteeEmailHash(generateCommitteEmailHash());
      if (random.nextInt(100) > 5)       sub.addAttachment(new File(Play.applicationPath + File.separator + "String_Node_Str"),AttachmentType.PRIMARY);
      if (random.nextInt(100) > 20) {
        Date agreementDate=generateRandomDate(random,2,2010);
        String stampedLicense=stampLicense(settingRepo.getConfigValue(SUBMIT_LICENSE_TEXT),agreementDate);
        sub.addAttachment(stampedLicense.getBytes(),"String_Node_Str",AttachmentType.LICENSE);
        sub.setLicenseAgreementDate(agreementDate);
      }
      if (random.nextInt(100) > 35) {
        Date agreementDate=generateRandomDate(random,2,2010);
        String stampedLicense=stampLicense(settingRepo.getConfigValue(PROQUEST_LICENSE_TEXT),agreementDate);
        sub.addAttachment(stampedLicense.getBytes(),"String_Node_Str",AttachmentType.LICENSE);
      }
      if (random.nextInt(100) > 75)       sub.addAttachment(new File(Play.applicationPath + File.separator + "String_Node_Str"),AttachmentType.SUPPLEMENTAL);
      if (random.nextInt(100) > 75)       sub.addAttachment(new File(Play.applicationPath + File.separator + "String_Node_Str"),AttachmentType.SUPPLEMENTAL);
      if (random.nextInt(100) > 50)       sub.addAttachment(new File(Play.applicationPath + File.separator + "String_Node_Str"),AttachmentType.FEEDBACK);
      context.turnOffAuthorization();
      if (random.nextInt(100) > 50)       sub.setReviewerNotes(generateRandomTitle(random));
      context.restoreAuthorization();
    }
    sub.save();
    context.logout();
    if (i > 0) {
      context.login(reviewer);
      int actionLogs=random.nextInt(30) + 10;
      for (int l=0; l < actionLogs; l++) {
        if (random.nextInt(100) > 30) {
          sub.logAction("String_Node_Str");
        }
 else {
          State state=sub.getState();
          List<State> transitions=state.getTransitions(sub);
          if (transitions.size() == 0)           transitions=stateManager.getAllStates();
          if (transitions.size() == 1) {
            sub.setState(transitions.get(0));
          }
 else {
            sub.setState(transitions.get(random.nextInt(transitions.size() - 1)));
          }
        }
        sub.save();
      }
      context.logout();
    }
    if (i > 0 && i % 100 == 0) {
      JPA.em().getTransaction().commit();
      JPA.em().clear();
      JPA.em().getTransaction().begin();
      embargos=settingRepo.findAllEmbargoTypes();
      reviewer=personRepo.findPersonByEmail("String_Node_Str");
      Logger.debug("String_Node_Str" + i + "String_Node_Str"+ ((System.currentTimeMillis() - start) / i)+ "String_Node_Str");
    }
  }
  Logger.debug("String_Node_Str" + howMany + "String_Node_Str"+ ((System.currentTimeMillis() - start) / howMany)+ "String_Node_Str");
  JPA.em().getTransaction().commit();
  JPA.em().clear();
  JPA.em().getTransaction().begin();
}

Fixed version (ground truth):
/** 
 * Load randomly generated submissions.
 */
public static void loadSubmissions(long seed,int howMany) throws IOException {
  List<EmbargoType> embargos=settingRepo.findAllEmbargoTypes();
  Person reviewer=personRepo.findPersonByEmail("String_Node_Str");
  Random random=new Random(seed);
  long start=System.currentTimeMillis();
  for (int i=0; i < howMany; i++) {
    context.turnOffAuthorization();
    Person student=personRepo.findPersonByNetId("String_Node_Str" + i);
    if (student == null) {
      String[] studentName=generateRandomName(random,ACTOR_NAMES);
      String studentEmail=generateRandomEmail(random,studentName);
      studentEmail=studentEmail.replaceFirst("String_Node_Str",(i + 1) + "String_Node_Str");
      student=personRepo.createPerson("String_Node_Str" + i,studentEmail,studentName[0],studentName[1],RoleType.STUDENT).save();
      if (i > 0) {
        student.setMiddleName(studentName[2]);
        student.setPassword("String_Node_Str");
        student.setCurrentPhoneNumber("String_Node_Str");
        student.setCurrentPostalAddress("String_Node_Str");
        student.setPermanentPhoneNumber("String_Node_Str");
        student.setPermanentPostalAddress("String_Node_Str");
        student.setPermanentEmailAddress("String_Node_Str");
        student.setInstitutionalIdentifier("String_Node_Str" + random.nextInt(9) + random.nextInt(9)+ random.nextInt(9)+ random.nextInt(9)+ random.nextInt(9)+ random.nextInt(9)+ random.nextInt(9)+ random.nextInt(9)+ random.nextInt(9));
        if (random.nextInt(100) > 50)         student.setOrcid("String_Node_Str" + random.nextInt(9) + random.nextInt(9)+ random.nextInt(9)+ random.nextInt(9)+ "String_Node_Str"+ random.nextInt(9)+ random.nextInt(9)+ random.nextInt(9)+ random.nextInt(9)+ "String_Node_Str"+ random.nextInt(9)+ random.nextInt(9)+ random.nextInt(9)+ random.nextInt(9)+ "String_Node_Str"+ random.nextInt(9)+ random.nextInt(9)+ random.nextInt(9)+ random.nextInt(9));
      }
      student.save();
    }
    String[] studentName=new String[3];
    studentName[0]=student.getFirstName();
    studentName[1]=student.getLastName();
    studentName[2]=student.getMiddleName();
    context.restoreAuthorization();
    context.login(student);
    Submission sub=subRepo.createSubmission(student).save();
    if (i > 0) {
      sub.setStudentFirstName(studentName[0]);
      sub.setStudentLastName(studentName[1]);
      sub.setStudentMiddleName(studentName[2]);
      if (random.nextInt(100) > 30)       sub.setStudentBirthYear(random.nextInt(20) + 1980);
      if (random.nextInt(100) > 5)       sub.addEmbargoType(embargos.get(random.nextInt(embargos.size() - 1)));
      int members=random.nextInt(5);
      String[] firstMemberName=null;
      for (int m=0; m < members; m++) {
        String[] memberName=generateRandomName(random,FAMOUS_NAMES);
        if (firstMemberName == null)         firstMemberName=memberName;
        CommitteeMember member=sub.addCommitteeMember(memberName[0],memberName[1],memberName[2]).save();
        if (random.nextInt(100) > 75) {
          DegreeLevelArray role=ROLETYPES_DEFINITIONS[random.nextInt(ROLETYPES_DEFINITIONS.length - 1)];
          member.addRole(role.name);
          if (random.nextInt(100) > 75) {
            role=ROLETYPES_DEFINITIONS[random.nextInt(ROLETYPES_DEFINITIONS.length - 1)];
            try {
              member.addRole(role.name);
            }
 catch (            IllegalArgumentException iae) {
            }
            ;
          }
        }
        member.save();
      }
      if (random.nextInt(100) > 5 && firstMemberName != null)       sub.setCommitteeContactEmail(generateRandomEmail(random,firstMemberName));
      if (random.nextInt(100) > 5) {
        DegreeLevelArray degree=DEGREES_DEFINITIONS[random.nextInt(DEGREES_DEFINITIONS.length - 1)];
        sub.setDegree(degree.name);
        sub.setDegreeLevel(degree.degreeLevel);
      }
      if (random.nextInt(100) > 5)       sub.setDocumentTitle(generateRandomTitle(random));
      if (random.nextInt(100) > 5)       sub.setDocumentAbstract(generateRandomAbstract(random));
      if (random.nextInt(100) > 5)       sub.setDocumentKeywords(generateRandomKeywords(random));
      if (random.nextInt(100) > 5) {
        List<ProquestSubject> subjects=proquestRepo.findAllSubjects();
        sub.addDocumentSubject(subjects.get(random.nextInt(subjects.size() - 1)).getDescription());
        if (random.nextInt(100) > 5) {
          sub.addDocumentSubject(subjects.get(random.nextInt(subjects.size() - 1)).getDescription());
          if (random.nextInt(100) > 5) {
            sub.addDocumentSubject(subjects.get(random.nextInt(subjects.size() - 1)).getDescription());
          }
        }
      }
      if (random.nextInt(100) > 5) {
        sub.setDocumentLanguage(LANGUAGES_DEFINITIONS[random.nextInt(LANGUAGES_DEFINITIONS.length)]);
      }
      if (random.nextInt(100) > 5)       sub.setDepartment(DEPARTMENTS_DEFINITIONS[random.nextInt(DEPARTMENTS_DEFINITIONS.length - 1)].name);
      if (random.nextInt(100) > 5)       sub.setProgram(PROGRAMS_DEFINITIONS[random.nextInt(PROGRAMS_DEFINITIONS.length - 1)].name);
      if (random.nextInt(100) > 5)       sub.setCollege(COLLEGES_DEFINITIONS[random.nextInt(COLLEGES_DEFINITIONS.length - 1)].name);
      if (random.nextInt(100) > 5)       sub.setMajor(MAJORS_DEFINITIONS[random.nextInt(MAJORS_DEFINITIONS.length - 1)]);
      if (random.nextInt(100) > 5)       sub.setDocumentType(DOCTYPES_DEFINITIONS[random.nextInt(DOCTYPES_DEFINITIONS.length - 1)].name);
      if (random.nextInt(100) > 5) {
        sub.setGraduationYear(random.nextInt(10) + 2002);
        sub.setGraduationMonth(GRAD_MONTHS_DEFINITIONS[random.nextInt(GRAD_MONTHS_DEFINITIONS.length - 1)]);
      }
      if (random.nextInt(100) > 50)       sub.setDefenseDate(generateRandomDate(random,2,2010));
      if (random.nextInt(100) > 5)       sub.setUMIRelease(random.nextBoolean());
      if (random.nextInt(100) > 5)       sub.setSubmissionDate(generateRandomDate(random,2,2010));
      if (random.nextInt(100) > 70)       sub.setApprovalDate(generateRandomDate(random,2,2010));
      if (random.nextInt(100) > 50)       sub.setCommitteeEmbargoApprovalDate(generateRandomDate(random,2,2010));
      if (random.nextInt(100) > 50)       sub.setCommitteeApprovalDate(generateRandomDate(random,2,2010));
      if (random.nextInt(100) > 5)       sub.setCommitteeEmailHash(generateCommitteEmailHash());
      if (random.nextInt(100) > 5)       sub.addAttachment(new File(Play.applicationPath + File.separator + "String_Node_Str"),AttachmentType.PRIMARY);
      if (random.nextInt(100) > 20) {
        Date agreementDate=generateRandomDate(random,2,2010);
        String stampedLicense=stampLicense(settingRepo.getConfigValue(SUBMIT_LICENSE_TEXT),agreementDate);
        sub.addAttachment(stampedLicense.getBytes(),"String_Node_Str",AttachmentType.LICENSE);
        sub.setLicenseAgreementDate(agreementDate);
      }
      if (random.nextInt(100) > 35) {
        Date agreementDate=generateRandomDate(random,2,2010);
        String stampedLicense=stampLicense(settingRepo.getConfigValue(PROQUEST_LICENSE_TEXT),agreementDate);
        sub.addAttachment(stampedLicense.getBytes(),"String_Node_Str",AttachmentType.LICENSE);
      }
      if (random.nextInt(100) > 75)       sub.addAttachment(new File(Play.applicationPath + File.separator + "String_Node_Str"),AttachmentType.SUPPLEMENTAL);
      if (random.nextInt(100) > 75)       sub.addAttachment(new File(Play.applicationPath + File.separator + "String_Node_Str"),AttachmentType.SUPPLEMENTAL);
      if (random.nextInt(100) > 50)       sub.addAttachment(new File(Play.applicationPath + File.separator + "String_Node_Str"),AttachmentType.FEEDBACK);
      context.turnOffAuthorization();
      if (random.nextInt(100) > 50)       sub.setReviewerNotes(generateRandomTitle(random));
      context.restoreAuthorization();
    }
    sub.save();
    context.logout();
    if (i > 0) {
      context.login(reviewer);
      int actionLogs=random.nextInt(30) + 10;
      for (int l=0; l < actionLogs; l++) {
        if (random.nextInt(100) > 30) {
          sub.logAction("String_Node_Str");
        }
 else {
          State state=sub.getState();
          List<State> transitions=state.getTransitions(sub);
          if (transitions.size() == 0)           transitions=stateManager.getAllStates();
          if (transitions.size() == 1) {
            sub.setState(transitions.get(0));
          }
 else {
            sub.setState(transitions.get(random.nextInt(transitions.size() - 1)));
          }
        }
        sub.save();
      }
      context.logout();
    }
    if (i > 0 && i % 100 == 0) {
      JPA.em().getTransaction().commit();
      JPA.em().clear();
      JPA.em().getTransaction().begin();
      embargos=settingRepo.findAllEmbargoTypes();
      reviewer=personRepo.findPersonByEmail("String_Node_Str");
      Logger.debug("String_Node_Str" + i + "String_Node_Str"+ ((System.currentTimeMillis() - start) / i)+ "String_Node_Str");
    }
  }
  Logger.debug("String_Node_Str" + howMany + "String_Node_Str"+ ((System.currentTimeMillis() - start) / howMany)+ "String_Node_Str");
  JPA.em().getTransaction().commit();
  JPA.em().clear();
  JPA.em().getTransaction().begin();
}