Program: 189308
Project: 189308
Buggy source:
/** 
 * Load all predefined settings. Colleges, departments, majors, degrees, document types, graduation month, and embargo definitions.
 */
public static void loadSettings() throws IOException {
  for (  ConfigurationArray config : CONFIG_DEFINITIONS) {
    settingRepo.createConfiguration(config.name,config.value).save();
  }
  for (  ProgramsArray programDefinition : PROGRAMS_DEFINITIONS) {
    settingRepo.createProgram(programDefinition.name,programDefinition.emails).save();
  }
  for (  CollegesArray collegeDefinition : COLLEGES_DEFINITIONS) {
    settingRepo.createCollege(collegeDefinition.name,collegeDefinition.emails).save();
  }
  for (  DepartmentsArray departmentDefinition : DEPARTMENTS_DEFINITIONS) {
    settingRepo.createDepartment(departmentDefinition.name,departmentDefinition.emails).save();
  }
  for (  String majorDefinition : MAJORS_DEFINITIONS) {
    settingRepo.createMajor(majorDefinition).save();
  }
  for (  DegreeLevelArray degreeDefinition : DEGREES_DEFINITIONS) {
    settingRepo.createDegree(degreeDefinition.name,degreeDefinition.degreeLevel).save();
  }
  for (  DegreeLevelArray docTypeDefinition : DOCTYPES_DEFINITIONS) {
    settingRepo.createDocumentType(docTypeDefinition.name,docTypeDefinition.degreeLevel).save();
  }
  for (  DegreeLevelArray roleTypeDefinition : ROLETYPES_DEFINITIONS) {
    settingRepo.createCommitteeMemberRoleType(roleTypeDefinition.name,roleTypeDefinition.degreeLevel).save();
  }
  for (  int gradMonthDefinition : GRAD_MONTHS_DEFINITIONS) {
    settingRepo.createGraduationMonth(gradMonthDefinition).save();
  }
  for (  EmbargoArray embargoDefinition : EMBARGO_DEFINTITIONS) {
    settingRepo.createEmbargoType(embargoDefinition.name,embargoDefinition.description,embargoDefinition.duration,embargoDefinition.active,embargoDefinition.guarantor).save();
  }
  for (  String actionDefinition : CUSTOM_ACTIONS_DEFINITIONS) {
    settingRepo.createCustomActionDefinition(actionDefinition,false).save();
  }
  systemEmailService.generateAllSystemEmailTemplates();
  for (  EmailTemplateArray templateDefinition : EMAIL_TEMPLATE_DEFINITIONS) {
    settingRepo.createEmailTemplate(templateDefinition.name,templateDefinition.subject,templateDefinition.message).save();
  }
  for (  AdministrativeGroupsArray adminGroupDefinition : ADMINISTRATIVE_GROUPS) {
    settingRepo.createAdministrativeGroup(adminGroupDefinition.name,adminGroupDefinition.emails).save();
  }
  for (  EmailWorkflowRulesArray ruleDefinition : EMAIL_WORKFLOW_RULES) {
    State ruleState=stateManager.getState(ruleDefinition.associatedState);
    EmailWorkflowRule wferule=settingRepo.createEmailWorkflowRule(ruleState);
    JpaEmailWorkflowRuleConditionImpl condition=(JpaEmailWorkflowRuleConditionImpl)settingRepo.createEmailWorkflowRuleCondition(ruleDefinition.condition.conditionType);
    if (ruleDefinition.condition.conditionId == null) {
switch (condition.conditionType) {
case Always:
        break;
case College:
      ruleDefinition.condition.conditionId=settingRepo.findAllColleges().get(0).getId();
    break;
case Department:
  ruleDefinition.condition.conditionId=settingRepo.findAllDepartments().get(0).getId();
break;
case Program:
ruleDefinition.condition.conditionId=settingRepo.findAllPrograms().get(0).getId();
break;
default :
throw new UnsupportedOperationException();
}
}
condition.setConditionId(ruleDefinition.condition.conditionId);
condition.save();
wferule.setCondition(condition);
JpaEmailTemplateImpl emailTemplate=(JpaEmailTemplateImpl)settingRepo.findEmailTemplateByName(ruleDefinition.emailTemplate.name);
wferule.setEmailTemplate(emailTemplate);
wferule.setRecipientType(ruleDefinition.recipientType);
if (ruleDefinition.adminGroupRecipient == null && ruleDefinition.recipientType == RecipientType.AdminGroup) {
ruleDefinition.adminGroupRecipient=settingRepo.findAllAdministrativeGroups().get(0).getId();
}
if (ruleDefinition.adminGroupRecipient != null) {
JpaAdministrativeGroupImpl adminGroup=(JpaAdministrativeGroupImpl)settingRepo.findAdministrativeGroup(ruleDefinition.adminGroupRecipient);
wferule.setAdminGroupRecipient(adminGroup);
}
 else {
wferule.setAdminGroupRecipient(null);
}
wferule.enable();
wferule.save();
}
for (DepositLocationArray locationDefinition : DEPOSIT_LOCATION_DEFINITIONS) {
Depositor depositor=(Depositor)Spring.getBean(locationDefinition.depositor);
Packager packager=(Packager)Spring.getBean(locationDefinition.packager);
DepositLocation location=settingRepo.createDepositLocation(locationDefinition.name);
location.setRepository(locationDefinition.repository);
location.setCollection(locationDefinition.collection);
location.setUsername(locationDefinition.username);
location.setPassword(locationDefinition.password);
location.setOnBehalfOf(locationDefinition.onBehalfOf);
location.setDepositor(depositor);
location.setPackager(packager);
if (depositor instanceof FileDepositorImpl) {
File baseDir=((FileDepositorImpl)depositor).baseDir;
FileUtils.forceMkdir(baseDir);
location.setCollection(new File(baseDir.getCanonicalPath() + File.separator + locationDefinition.collection).getCanonicalPath());
}
location.save();
}
for (String languageDefinition : LANGUAGES_DEFINITIONS) {
settingRepo.createLanguage(languageDefinition).save();
}
}

Fixed version (ground truth):
/** 
 * Load all predefined settings. Colleges, departments, majors, degrees, document types, graduation month, and embargo definitions.
 */
public static void loadSettings() throws IOException {
  for (  ConfigurationArray config : CONFIG_DEFINITIONS) {
    settingRepo.createConfiguration(config.name,config.value).save();
  }
  for (  ProgramsArray programDefinition : PROGRAMS_DEFINITIONS) {
    settingRepo.createProgram(programDefinition.name,programDefinition.emails).save();
  }
  for (  CollegesArray collegeDefinition : COLLEGES_DEFINITIONS) {
    settingRepo.createCollege(collegeDefinition.name,collegeDefinition.emails).save();
  }
  for (  DepartmentsArray departmentDefinition : DEPARTMENTS_DEFINITIONS) {
    settingRepo.createDepartment(departmentDefinition.name,departmentDefinition.emails).save();
  }
  for (  String majorDefinition : MAJORS_DEFINITIONS) {
    settingRepo.createMajor(majorDefinition).save();
  }
  for (  DegreeLevelArray degreeDefinition : DEGREES_DEFINITIONS) {
    settingRepo.createDegree(degreeDefinition.name,degreeDefinition.degreeLevel).save();
  }
  for (  DegreeLevelArray docTypeDefinition : DOCTYPES_DEFINITIONS) {
    settingRepo.createDocumentType(docTypeDefinition.name,docTypeDefinition.degreeLevel).save();
  }
  for (  DegreeLevelArray roleTypeDefinition : ROLETYPES_DEFINITIONS) {
    settingRepo.createCommitteeMemberRoleType(roleTypeDefinition.name,roleTypeDefinition.degreeLevel).save();
  }
  for (  int gradMonthDefinition : GRAD_MONTHS_DEFINITIONS) {
    settingRepo.createGraduationMonth(gradMonthDefinition).save();
  }
  for (  EmbargoArray embargoDefinition : EMBARGO_DEFINTITIONS) {
    EmbargoType embargo=settingRepo.createEmbargoType(embargoDefinition.name,embargoDefinition.description,embargoDefinition.duration,embargoDefinition.active,embargoDefinition.guarantor);
    embargo.setSystemRequired(embargoDefinition.isSystem);
    embargo.save();
  }
  for (  String actionDefinition : CUSTOM_ACTIONS_DEFINITIONS) {
    settingRepo.createCustomActionDefinition(actionDefinition,false).save();
  }
  systemEmailService.generateAllSystemEmailTemplates();
  for (  EmailTemplateArray templateDefinition : EMAIL_TEMPLATE_DEFINITIONS) {
    settingRepo.createEmailTemplate(templateDefinition.name,templateDefinition.subject,templateDefinition.message).save();
  }
  for (  AdministrativeGroupsArray adminGroupDefinition : ADMINISTRATIVE_GROUPS) {
    settingRepo.createAdministrativeGroup(adminGroupDefinition.name,adminGroupDefinition.emails).save();
  }
  for (  EmailWorkflowRulesArray ruleDefinition : EMAIL_WORKFLOW_RULES) {
    State ruleState=stateManager.getState(ruleDefinition.associatedState);
    EmailWorkflowRule wferule=settingRepo.createEmailWorkflowRule(ruleState);
    JpaEmailWorkflowRuleConditionImpl condition=(JpaEmailWorkflowRuleConditionImpl)settingRepo.createEmailWorkflowRuleCondition(ruleDefinition.condition.conditionType);
    if (ruleDefinition.condition.conditionId == null) {
switch (condition.conditionType) {
case Always:
        break;
case College:
      ruleDefinition.condition.conditionId=settingRepo.findAllColleges().get(0).getId();
    break;
case Department:
  ruleDefinition.condition.conditionId=settingRepo.findAllDepartments().get(0).getId();
break;
case Program:
ruleDefinition.condition.conditionId=settingRepo.findAllPrograms().get(0).getId();
break;
default :
throw new UnsupportedOperationException();
}
}
condition.setConditionId(ruleDefinition.condition.conditionId);
condition.save();
wferule.setCondition(condition);
JpaEmailTemplateImpl emailTemplate=(JpaEmailTemplateImpl)settingRepo.findEmailTemplateByName(ruleDefinition.emailTemplate.name);
wferule.setEmailTemplate(emailTemplate);
wferule.setRecipientType(ruleDefinition.recipientType);
if (ruleDefinition.adminGroupRecipient == null && ruleDefinition.recipientType == RecipientType.AdminGroup) {
ruleDefinition.adminGroupRecipient=settingRepo.findAllAdministrativeGroups().get(0).getId();
}
if (ruleDefinition.adminGroupRecipient != null) {
JpaAdministrativeGroupImpl adminGroup=(JpaAdministrativeGroupImpl)settingRepo.findAdministrativeGroup(ruleDefinition.adminGroupRecipient);
wferule.setAdminGroupRecipient(adminGroup);
}
 else {
wferule.setAdminGroupRecipient(null);
}
wferule.enable();
wferule.save();
}
for (DepositLocationArray locationDefinition : DEPOSIT_LOCATION_DEFINITIONS) {
Depositor depositor=(Depositor)Spring.getBean(locationDefinition.depositor);
Packager packager=(Packager)Spring.getBean(locationDefinition.packager);
DepositLocation location=settingRepo.createDepositLocation(locationDefinition.name);
location.setRepository(locationDefinition.repository);
location.setCollection(locationDefinition.collection);
location.setUsername(locationDefinition.username);
location.setPassword(locationDefinition.password);
location.setOnBehalfOf(locationDefinition.onBehalfOf);
location.setDepositor(depositor);
location.setPackager(packager);
if (depositor instanceof FileDepositorImpl) {
File baseDir=((FileDepositorImpl)depositor).baseDir;
FileUtils.forceMkdir(baseDir);
location.setCollection(new File(baseDir.getCanonicalPath() + File.separator + locationDefinition.collection).getCanonicalPath());
}
location.save();
}
for (String languageDefinition : LANGUAGES_DEFINITIONS) {
settingRepo.createLanguage(languageDefinition).save();
}
}