Program: 189369
Project: 189369
Buggy source:
/** 
 * This static class will take a submission and go through all of the JPA email rules to decide if an email needs to be sent (and to whom) depending on the rule's condition and recipients
 * @param submission - the submission
 */
public static void runEmailRules(Submission submission){
  SettingsRepository settingRepo=Spring.getBeanOfType(SettingsRepository.class);
  List<WorkflowEmailRule> rules=settingRepo.findAllWorkflowEmailRules();
  for (  WorkflowEmailRule workflowEmailRule : rules) {
    if (ruleIsValid(workflowEmailRule,submission)) {
      if (workflowEmailRule.getAssociatedState().equals(submission.getState().getBeanName())) {
switch (workflowEmailRule.getCondition().getConditionType()) {
case Always:
          sendEmail(workflowEmailRule,submission);
        break;
case College:
      Long collegeId=workflowEmailRule.getCondition().getConditionId();
    College ruleCollege=settingRepo.findCollege(collegeId);
  if (ruleCollege.getName().equals(submission.getCollege())) {
    sendEmail(workflowEmailRule,submission);
  }
break;
case Department:
Long departmentId=workflowEmailRule.getCondition().getConditionId();
Department ruleDepartment=settingRepo.findDepartment(departmentId);
if (ruleDepartment.getName().equals(submission.getDepartment())) {
sendEmail(workflowEmailRule,submission);
}
break;
case Program:
Long programId=workflowEmailRule.getCondition().getConditionId();
Program ruleProgram=settingRepo.findProgram(programId);
if (ruleProgram.getName().equals(submission.getProgram())) {
sendEmail(workflowEmailRule,submission);
}
break;
default :
throw new UnsupportedOperationException();
}
}
}
}
}

Fixed version (ground truth):
/** 
 * This static class will take a submission and go through all of the JPA email rules to decide if an email needs to be sent (and to whom) depending on the rule's condition and recipients
 * @param submission - the submission
 */
public static void runEmailRules(Submission submission){
  SettingsRepository settingRepo=Spring.getBeanOfType(SettingsRepository.class);
  List<WorkflowEmailRule> rules=settingRepo.findAllWorkflowEmailRules();
  for (  WorkflowEmailRule workflowEmailRule : rules) {
    if (ruleIsValid(workflowEmailRule,submission)) {
      if (workflowEmailRule.getAssociatedState().getBeanName().equals(submission.getState().getBeanName())) {
switch (workflowEmailRule.getCondition().getConditionType()) {
case Always:
          sendEmail(workflowEmailRule,submission);
        break;
case College:
      Long collegeId=workflowEmailRule.getCondition().getConditionId();
    College ruleCollege=settingRepo.findCollege(collegeId);
  if (ruleCollege != null && ruleCollege.getName().equals(submission.getCollege())) {
    sendEmail(workflowEmailRule,submission);
  }
break;
case Department:
Long departmentId=workflowEmailRule.getCondition().getConditionId();
Department ruleDepartment=settingRepo.findDepartment(departmentId);
if (ruleDepartment != null && ruleDepartment.getName().equals(submission.getDepartment())) {
sendEmail(workflowEmailRule,submission);
}
break;
case Program:
Long programId=workflowEmailRule.getCondition().getConditionId();
Program ruleProgram=settingRepo.findProgram(programId);
if (ruleProgram != null && ruleProgram.getName().equals(submission.getProgram())) {
sendEmail(workflowEmailRule,submission);
}
break;
default :
throw new UnsupportedOperationException();
}
}
}
}
}