Program: 189355
Project: 189355
Buggy source:
/** 
 * The third step of the submission form. We handle committee members a bit differently. Basically we always keep a List of Maps for each committee member while we are working with it. So there are several methods to parse the committee members from the current form data, validate the committee members, then save the committee members, and if this is the first time visiting the form there is a method to load committee members. It's complex, but the problem is Difficult.
 * @param subId The id the submission.
 */
@Security(RoleType.STUDENT) public static void documentInfo(Long subId){
  Submission sub=getSubmission();
  String title=params.get("String_Node_Str");
  String degreeMonth=params.get("String_Node_Str");
  String degreeYear=params.get("String_Node_Str");
  Date defenseDate=null;
  DateFormat formatter=new SimpleDateFormat("String_Node_Str");
  try {
    if (params.get("String_Node_Str") != null && !"String_Node_Str".equals(params.get("String_Node_Str").trim()))     defenseDate=(Date)formatter.parse(params.get("String_Node_Str"));
  }
 catch (  ParseException e) {
    validation.addError("String_Node_Str","String_Node_Str");
  }
  String docType=params.get("String_Node_Str");
  String abstractText=params.get("String_Node_Str");
  String keywords=params.get("String_Node_Str");
  String subjectPrimary=params.get("String_Node_Str");
  String subjectSecondary=params.get("String_Node_Str");
  String subjectTertiary=params.get("String_Node_Str");
  String docLanguage=null;
  if (isFieldRequired(DOCUMENT_LANGUAGE) && settingRepo.findAllLanguages().size() == 1) {
    docLanguage=settingRepo.findAllLanguages().get(0).getName();
  }
 else {
    docLanguage=params.get("String_Node_Str");
    if (docLanguage != null && docLanguage.trim().length() == 0)     docLanguage=null;
  }
  Boolean publishedMaterialFlag=params.get("String_Node_Str",Boolean.class);
  if (publishedMaterialFlag == null)   publishedMaterialFlag=false;
  String publishedMaterial=params.get("String_Node_Str");
  if (!publishedMaterialFlag)   publishedMaterial=null;
  String chairEmail=params.get("String_Node_Str");
  String embargosString=params.get("String_Node_Str");
  List<String> embargos=new ArrayList<String>();
  if (embargosString != null)   for (  String embargo : embargosString.split("String_Node_Str")) {
    embargos.add(embargo);
  }
  List<TransientMember> committee=parseCommitteeMembers();
  if ("String_Node_Str".equals(params.get("String_Node_Str"))) {
    if (isFieldEnabled(DOCUMENT_TITLE))     sub.setDocumentTitle(title);
    if (isFieldEnabled(GRADUATION_DATE)) {
      if (!isEmpty(degreeMonth)) {
        try {
          sub.setGraduationMonth(Integer.parseInt(degreeMonth));
        }
 catch (        RuntimeException re) {
          validation.addError("String_Node_Str","String_Node_Str");
        }
      }
 else {
        sub.setGraduationMonth(null);
      }
      if (!isEmpty(degreeYear)) {
        try {
          sub.setGraduationYear(Integer.parseInt(degreeYear));
        }
 catch (        RuntimeException re) {
          validation.addError("String_Node_Str","String_Node_Str");
        }
      }
 else {
        sub.setGraduationYear(null);
      }
    }
    if (isFieldEnabled(DEFENSE_DATE)) {
      sub.setDefenseDate(defenseDate);
    }
    if (isFieldEnabled(DOCUMENT_TYPE))     sub.setDocumentType(docType);
    if (isFieldEnabled(DOCUMENT_ABSTRACT))     sub.setDocumentAbstract(abstractText);
    if (isFieldEnabled(DOCUMENT_KEYWORDS))     sub.setDocumentKeywords(keywords);
    if (isFieldEnabled(DOCUMENT_SUBJECTS)) {
      sub.getDocumentSubjects().clear();
      if (!isEmpty(subjectPrimary))       sub.addDocumentSubject(subjectPrimary);
      if (!isEmpty(subjectSecondary))       sub.addDocumentSubject(subjectSecondary);
      if (!isEmpty(subjectTertiary))       sub.addDocumentSubject(subjectTertiary);
    }
    if (isFieldEnabled(DOCUMENT_LANGUAGE))     sub.setDocumentLanguage(docLanguage);
    if (isFieldEnabled(COMMITTEE_CONTACT_EMAIL))     sub.setCommitteeContactEmail(chairEmail);
    if (isFieldEnabled(PUBLISHED_MATERIAL)) {
      if (publishedMaterialFlag)       sub.setPublishedMaterial(publishedMaterial);
 else       sub.setPublishedMaterial(null);
    }
    if (isFieldEnabled(EMBARGO_TYPE)) {
      for (      String embargo : embargos) {
        try {
          sub.addEmbargoType(settingRepo.findEmbargoType(Long.parseLong(embargo)));
        }
 catch (        RuntimeException re) {
          if (isFieldRequired(EMBARGO_TYPE))           validation.addError("String_Node_Str","String_Node_Str");
        }
      }
    }
    if (isFieldEnabled(COMMITTEE)) {
      try {
        saveCommitteeMembers(sub,committee);
      }
 catch (      RuntimeException re) {
      }
    }
    sub.save();
  }
 else {
    if (isFieldEnabled(DOCUMENT_TITLE))     title=sub.getDocumentTitle();
    if (isFieldEnabled(GRADUATION_DATE) && sub.getGraduationMonth() != null)     degreeMonth=sub.getGraduationMonth().toString();
    if (isFieldEnabled(GRADUATION_DATE) && sub.getGraduationYear() != null)     degreeYear=sub.getGraduationYear().toString();
    if (isFieldEnabled(DEFENSE_DATE) && sub.getDefenseDate() != null)     defenseDate=sub.getDefenseDate();
    if (isFieldEnabled(DOCUMENT_TYPE))     docType=sub.getDocumentType();
    if (isFieldEnabled(DOCUMENT_ABSTRACT))     abstractText=sub.getDocumentAbstract();
    if (isFieldEnabled(DOCUMENT_KEYWORDS))     keywords=sub.getDocumentKeywords();
    if (isFieldEnabled(DOCUMENT_SUBJECTS)) {
      List<String> subjects=sub.getDocumentSubjects();
      if (subjects.size() > 0)       subjectPrimary=subjects.get(0);
      if (subjects.size() > 1)       subjectSecondary=subjects.get(1);
      if (subjects.size() > 2)       subjectTertiary=subjects.get(2);
    }
    if (isFieldEnabled(DOCUMENT_LANGUAGE)) {
      docLanguage=sub.getDocumentLanguage();
    }
    if (isFieldEnabled(COMMITTEE))     committee=loadCommitteeMembers(sub);
    if (isFieldEnabled(COMMITTEE_CONTACT_EMAIL))     chairEmail=sub.getCommitteeContactEmail();
    if (isFieldEnabled(PUBLISHED_MATERIAL))     publishedMaterial=sub.getPublishedMaterial();
  }
  if ("String_Node_Str".equals(params.get("String_Node_Str")) || "String_Node_Str".equals(flash.get("String_Node_Str"))) {
    verify(sub);
  }
  if (params.get("String_Node_Str") != null && !validation.hasErrors()) {
    FileUpload.fileUpload(subId);
  }
  List<Integer> degreeYears=getDegreeYears();
  renderArgs.put("String_Node_Str",degreeYears);
  List<String> docTypes=getValidDocumentTypes(sub);
  renderArgs.put("String_Node_Str",docTypes);
  List<EmbargoType> embargoTypes=settingRepo.findAllActiveEmbargoTypes();
  renderArgs.put("String_Node_Str",embargoTypes);
  List<ProquestSubject> subjects=proquestRepo.findAllSubjects();
  renderArgs.put("String_Node_Str",subjects);
  List<CommitteeMemberRoleType> availableRoles=settingRepo.findAllCommitteeMemberRoleTypes(sub.getDegreeLevel());
  renderArgs.put("String_Node_Str",availableRoles);
  List<Language> languages=settingRepo.findAllLanguages();
  renderArgs.put("String_Node_Str",languages);
  int committeeSlots=4;
  if (committee.size() > 3)   committeeSlots=committee.size();
  if (params.get("String_Node_Str") != null)   committeeSlots+=4;
  List<String> stickies=new ArrayList<String>();
  String stickiesRaw=settingRepo.getConfigValue(SUBMIT_DOCUMENT_INFO_STICKIES);
  if (stickiesRaw != null && !"String_Node_Str".equals(stickiesRaw)) {
    try {
      CSVReader reader=new CSVReader(new StringReader(stickiesRaw));
      stickies=Arrays.asList(reader.readNext());
      reader.close();
    }
 catch (    IOException ioe) {
      throw new RuntimeException(ioe);
    }
  }
  if (publishedMaterial != null)   publishedMaterialFlag=true;
  renderTemplate("String_Node_Str",subId,stickies,title,degreeMonth,degreeYear,defenseDate,docType,abstractText,keywords,subjectPrimary,subjectSecondary,subjectTertiary,docLanguage,committeeSlots,committee,chairEmail,publishedMaterialFlag,publishedMaterial,embargos);
}

Fixed version (ground truth):
/** 
 * The third step of the submission form. We handle committee members a bit differently. Basically we always keep a List of Maps for each committee member while we are working with it. So there are several methods to parse the committee members from the current form data, validate the committee members, then save the committee members, and if this is the first time visiting the form there is a method to load committee members. It's complex, but the problem is Difficult.
 * @param subId The id the submission.
 */
@Security(RoleType.STUDENT) public static void documentInfo(Long subId){
  Submission sub=getSubmission();
  String title=params.get("String_Node_Str");
  String degreeMonth=params.get("String_Node_Str");
  String degreeYear=params.get("String_Node_Str");
  Date defenseDate=null;
  DateFormat formatter=new SimpleDateFormat("String_Node_Str");
  try {
    if (params.get("String_Node_Str") != null && !"String_Node_Str".equals(params.get("String_Node_Str").trim()))     defenseDate=(Date)formatter.parse(params.get("String_Node_Str"));
  }
 catch (  ParseException e) {
    validation.addError("String_Node_Str","String_Node_Str");
  }
  String docType=params.get("String_Node_Str");
  String abstractText=params.get("String_Node_Str");
  String keywords=params.get("String_Node_Str");
  String subjectPrimary=params.get("String_Node_Str");
  String subjectSecondary=params.get("String_Node_Str");
  String subjectTertiary=params.get("String_Node_Str");
  String docLanguage=null;
  if (isFieldRequired(DOCUMENT_LANGUAGE) && settingRepo.findAllLanguages().size() == 1) {
    docLanguage=settingRepo.findAllLanguages().get(0).getName();
  }
 else {
    docLanguage=params.get("String_Node_Str");
    if (docLanguage != null && docLanguage.trim().length() == 0)     docLanguage=null;
  }
  Boolean publishedMaterialFlag=params.get("String_Node_Str",Boolean.class);
  if (publishedMaterialFlag == null)   publishedMaterialFlag=false;
  String publishedMaterial=params.get("String_Node_Str");
  if (!publishedMaterialFlag)   publishedMaterial=null;
  String chairEmail=params.get("String_Node_Str");
  List<String> embargos=new ArrayList<String>();
  for (  EmbargoGuarantor gaurantor : EmbargoGuarantor.values()) {
    String embargoString=params.get("String_Node_Str" + gaurantor.name());
    if (embargoString != null && embargoString.trim().length() != 0)     embargos.add(embargoString);
  }
  List<TransientMember> committee=parseCommitteeMembers();
  if ("String_Node_Str".equals(params.get("String_Node_Str"))) {
    if (isFieldEnabled(DOCUMENT_TITLE))     sub.setDocumentTitle(title);
    if (isFieldEnabled(GRADUATION_DATE)) {
      if (!isEmpty(degreeMonth)) {
        try {
          sub.setGraduationMonth(Integer.parseInt(degreeMonth));
        }
 catch (        RuntimeException re) {
          validation.addError("String_Node_Str","String_Node_Str");
        }
      }
 else {
        sub.setGraduationMonth(null);
      }
      if (!isEmpty(degreeYear)) {
        try {
          sub.setGraduationYear(Integer.parseInt(degreeYear));
        }
 catch (        RuntimeException re) {
          validation.addError("String_Node_Str","String_Node_Str");
        }
      }
 else {
        sub.setGraduationYear(null);
      }
    }
    if (isFieldEnabled(DEFENSE_DATE)) {
      sub.setDefenseDate(defenseDate);
    }
    if (isFieldEnabled(DOCUMENT_TYPE))     sub.setDocumentType(docType);
    if (isFieldEnabled(DOCUMENT_ABSTRACT))     sub.setDocumentAbstract(abstractText);
    if (isFieldEnabled(DOCUMENT_KEYWORDS))     sub.setDocumentKeywords(keywords);
    if (isFieldEnabled(DOCUMENT_SUBJECTS)) {
      sub.getDocumentSubjects().clear();
      if (!isEmpty(subjectPrimary))       sub.addDocumentSubject(subjectPrimary);
      if (!isEmpty(subjectSecondary))       sub.addDocumentSubject(subjectSecondary);
      if (!isEmpty(subjectTertiary))       sub.addDocumentSubject(subjectTertiary);
    }
    if (isFieldEnabled(DOCUMENT_LANGUAGE))     sub.setDocumentLanguage(docLanguage);
    if (isFieldEnabled(COMMITTEE_CONTACT_EMAIL))     sub.setCommitteeContactEmail(chairEmail);
    if (isFieldEnabled(PUBLISHED_MATERIAL)) {
      if (publishedMaterialFlag)       sub.setPublishedMaterial(publishedMaterial);
 else       sub.setPublishedMaterial(null);
    }
    if (isFieldEnabled(EMBARGO_TYPE)) {
      for (      String embargo : embargos) {
        try {
          Logger.info(embargo);
          sub.addEmbargoType(settingRepo.findEmbargoType(Long.parseLong(embargo)));
        }
 catch (        RuntimeException re) {
          if (isFieldRequired(EMBARGO_TYPE))           validation.addError("String_Node_Str","String_Node_Str");
        }
      }
    }
    if (isFieldEnabled(COMMITTEE)) {
      try {
        saveCommitteeMembers(sub,committee);
      }
 catch (      RuntimeException re) {
      }
    }
    sub.save();
  }
 else {
    if (isFieldEnabled(DOCUMENT_TITLE))     title=sub.getDocumentTitle();
    if (isFieldEnabled(GRADUATION_DATE) && sub.getGraduationMonth() != null)     degreeMonth=sub.getGraduationMonth().toString();
    if (isFieldEnabled(GRADUATION_DATE) && sub.getGraduationYear() != null)     degreeYear=sub.getGraduationYear().toString();
    if (isFieldEnabled(DEFENSE_DATE) && sub.getDefenseDate() != null)     defenseDate=sub.getDefenseDate();
    if (isFieldEnabled(DOCUMENT_TYPE))     docType=sub.getDocumentType();
    if (isFieldEnabled(DOCUMENT_ABSTRACT))     abstractText=sub.getDocumentAbstract();
    if (isFieldEnabled(DOCUMENT_KEYWORDS))     keywords=sub.getDocumentKeywords();
    if (isFieldEnabled(DOCUMENT_SUBJECTS)) {
      List<String> subjects=sub.getDocumentSubjects();
      if (subjects.size() > 0)       subjectPrimary=subjects.get(0);
      if (subjects.size() > 1)       subjectSecondary=subjects.get(1);
      if (subjects.size() > 2)       subjectTertiary=subjects.get(2);
    }
    if (isFieldEnabled(DOCUMENT_LANGUAGE)) {
      docLanguage=sub.getDocumentLanguage();
    }
    if (isFieldEnabled(COMMITTEE))     committee=loadCommitteeMembers(sub);
    if (isFieldEnabled(COMMITTEE_CONTACT_EMAIL))     chairEmail=sub.getCommitteeContactEmail();
    if (isFieldEnabled(PUBLISHED_MATERIAL))     publishedMaterial=sub.getPublishedMaterial();
    for (    EmbargoGuarantor eg : EmbargoGuarantor.values()) {
      String fieldName=eg.name().equals("String_Node_Str") ? "String_Node_Str" : "String_Node_Str" + eg.name();
      FieldConfig field=FieldConfig.valueOf(fieldName);
      System.out.println(sub.getEmbargoTypeByGuarantor(eg) != null);
      if (isFieldEnabled(field) && sub.getEmbargoTypeByGuarantor(eg) != null) {
        embargos.add(sub.getEmbargoTypeByGuarantor(eg).getId().toString());
      }
    }
  }
  if ("String_Node_Str".equals(params.get("String_Node_Str")) || "String_Node_Str".equals(flash.get("String_Node_Str"))) {
    verify(sub);
  }
  if (params.get("String_Node_Str") != null && !validation.hasErrors()) {
    FileUpload.fileUpload(subId);
  }
  List<Integer> degreeYears=getDegreeYears();
  renderArgs.put("String_Node_Str",degreeYears);
  List<String> docTypes=getValidDocumentTypes(sub);
  renderArgs.put("String_Node_Str",docTypes);
  List<EmbargoType> embargoTypes=settingRepo.findAllActiveEmbargoTypes();
  renderArgs.put("String_Node_Str",embargoTypes);
  List<ProquestSubject> subjects=proquestRepo.findAllSubjects();
  renderArgs.put("String_Node_Str",subjects);
  List<CommitteeMemberRoleType> availableRoles=settingRepo.findAllCommitteeMemberRoleTypes(sub.getDegreeLevel());
  renderArgs.put("String_Node_Str",availableRoles);
  List<Language> languages=settingRepo.findAllLanguages();
  renderArgs.put("String_Node_Str",languages);
  int committeeSlots=4;
  if (committee.size() > 3)   committeeSlots=committee.size();
  if (params.get("String_Node_Str") != null)   committeeSlots+=4;
  List<String> stickies=new ArrayList<String>();
  String stickiesRaw=settingRepo.getConfigValue(SUBMIT_DOCUMENT_INFO_STICKIES);
  if (stickiesRaw != null && !"String_Node_Str".equals(stickiesRaw)) {
    try {
      CSVReader reader=new CSVReader(new StringReader(stickiesRaw));
      stickies=Arrays.asList(reader.readNext());
      reader.close();
    }
 catch (    IOException ioe) {
      throw new RuntimeException(ioe);
    }
  }
  if (publishedMaterial != null)   publishedMaterialFlag=true;
  renderTemplate("String_Node_Str",subId,stickies,title,degreeMonth,degreeYear,defenseDate,docType,abstractText,keywords,subjectPrimary,subjectSecondary,subjectTertiary,docLanguage,committeeSlots,committee,chairEmail,publishedMaterialFlag,publishedMaterial,embargos);
}