nus-yam/ex-repair huggingface dataset:
Program: 98489
Project: 98489
Buggy source:
public List<CommentVo> getCommentsByCourseId(long courseId){
  EntityManager entityManager=null;
  List<CommentVo> commentVos;
  try {
    entityManager=getEntityManagerFactory().createEntityManager();
    commentVos=getServiceFactory().getCommentsService().getByCourseId(entityManager,courseId);
  }
 catch (  Exception exception) {
    getServiceFactory().getLogService().error(exception.getMessage(),exception);
    throw new RuntimeException(exception);
  }
 finally {
    FacadesHelper.closeEntityManager(entityManager);
  }
  return commentVos;
}

Fixed version (ground truth):
public List<CommentVo> getCommentsByCourseId(long courseId){
  EntityManager entityManager=null;
  List<CommentVo> commentVos;
  try {
    entityManager=getEntityManagerFactory().createEntityManager();
    commentVos=getServiceFactory().getCommentsService().getByCourseId(entityManager,courseId);
  }
 catch (  Exception exception) {
    getServiceFactory().getLogService().error(exception.getMessage(),exception);
    FacadesHelper.closeEntityManager(entityManager);
    throw new RuntimeException(exception);
  }
 finally {
    FacadesHelper.closeEntityManager(entityManager);
  }
  return commentVos;
}
Program: 98490
Project: 98490
Buggy source:
public BinaryRatingVo rateComment(long commentId,long userId,int value) throws MultipleMessagesException, DuplicityException {
  EntityManager entityManager=null;
  EntityTransaction transaction=null;
  BinaryRatingVo rating=null;
  try {
    entityManager=getEntityManagerFactory().createEntityManager();
    BinaryRatingVo existingRating=getServiceFactory().getCommentRatingService().getByEvaluatedObjectAndUserId(entityManager,commentId,userId);
    transaction=entityManager.getTransaction();
    transaction.begin();
    if (existingRating == null) {
      BinaryRatingVo vo=new BinaryRatingVo();
      vo.setEvaluatedObjectId(commentId);
      vo.setUserId(userId);
      vo.setValue(value);
      rating=getServiceFactory().getCommentRatingService().create(entityManager,vo);
    }
 else {
      existingRating.setValue(value);
      rating=getServiceFactory().getCommentRatingService().update(entityManager,existingRating);
    }
    transaction.commit();
  }
 catch (  Exception exception) {
    getServiceFactory().getLogService().error(exception.getMessage(),exception);
    FacadesHelper.checkException(exception,MultipleMessagesException.class);
    FacadesHelper.checkDuplicityViolation(entityManager,transaction,exception);
    FacadesHelper.rollbackTransaction(entityManager,transaction,exception);
  }
 finally {
    FacadesHelper.closeEntityManager(entityManager);
  }
  return rating;
}

Fixed version (ground truth):
public BinaryRatingVo rateComment(long commentId,long userId,int value) throws MultipleMessagesException, DuplicityException {
  EntityManager entityManager=null;
  EntityTransaction transaction=null;
  BinaryRatingVo rating=null;
  try {
    entityManager=getEntityManagerFactory().createEntityManager();
    BinaryRatingVo existingRating=getServiceFactory().getCommentRatingService().getByEvaluatedObjectAndUserId(entityManager,commentId,userId);
    transaction=entityManager.getTransaction();
    transaction.begin();
    if (existingRating == null) {
      BinaryRatingVo vo=new BinaryRatingVo();
      vo.setEvaluatedObjectId(commentId);
      vo.setUserId(userId);
      vo.setValue(value);
      rating=getServiceFactory().getCommentRatingService().create(entityManager,vo);
    }
 else {
      existingRating.setValue(value);
      rating=getServiceFactory().getCommentRatingService().update(entityManager,existingRating);
    }
    transaction.commit();
  }
 catch (  Exception exception) {
    getServiceFactory().getLogService().error(exception.getMessage(),exception);
    FacadesHelper.checkException(entityManager,exception,MultipleMessagesException.class);
    FacadesHelper.checkDuplicityViolation(entityManager,transaction,exception);
    FacadesHelper.rollbackTransactionAndCloseEntityManager(entityManager,transaction,exception);
  }
 finally {
    FacadesHelper.closeEntityManager(entityManager);
  }
  return rating;
}
Program: 98491
Project: 98491
Buggy source:
public CommentVo createComment(CommentVo vo) throws MultipleMessagesException, MaxCommentsLimitReachedException, DuplicityException {
  CommentVo createdVo=null;
  EntityManager entityManager=null;
  EntityTransaction transaction=null;
  try {
    entityManager=getEntityManagerFactory().createEntityManager();
    transaction=entityManager.getTransaction();
    transaction.begin();
    createdVo=getServiceFactory().getCommentsService().create(entityManager,vo);
    transaction.commit();
  }
 catch (  Exception exception) {
    getServiceFactory().getLogService().error(exception.getMessage(),exception);
    FacadesHelper.checkException(exception,MultipleMessagesException.class);
    FacadesHelper.checkException(exception,MaxCommentsLimitReachedException.class);
    FacadesHelper.checkDuplicityViolation(entityManager,transaction,exception);
    FacadesHelper.rollbackTransaction(entityManager,transaction,exception);
  }
 finally {
    FacadesHelper.closeEntityManager(entityManager);
  }
  return createdVo;
}

Fixed version (ground truth):
public CommentVo createComment(CommentVo vo) throws MultipleMessagesException, MaxCommentsLimitReachedException, DuplicityException {
  CommentVo createdVo=null;
  EntityManager entityManager=null;
  EntityTransaction transaction=null;
  try {
    entityManager=getEntityManagerFactory().createEntityManager();
    transaction=entityManager.getTransaction();
    transaction.begin();
    createdVo=getServiceFactory().getCommentsService().create(entityManager,vo);
    transaction.commit();
  }
 catch (  Exception exception) {
    getServiceFactory().getLogService().error(exception.getMessage(),exception);
    FacadesHelper.checkException(entityManager,exception,MultipleMessagesException.class);
    FacadesHelper.checkException(entityManager,exception,MaxCommentsLimitReachedException.class);
    FacadesHelper.checkDuplicityViolation(entityManager,transaction,exception);
    FacadesHelper.rollbackTransactionAndCloseEntityManager(entityManager,transaction,exception);
  }
 finally {
    FacadesHelper.closeEntityManager(entityManager);
  }
  return createdVo;
}
Program: 98492
Project: 98492
Buggy source:
public RatingSummaryVo getCommentRatingSummary(long commentId){
  EntityManager entityManager=null;
  RatingSummaryVo summary=null;
  try {
    entityManager=getEntityManagerFactory().createEntityManager();
    summary=getServiceFactory().getCommentRatingService().getSummary(entityManager,commentId);
  }
 catch (  Exception exception) {
    getServiceFactory().getLogService().error(exception.getMessage(),exception);
    throw new RuntimeException(exception);
  }
 finally {
    FacadesHelper.closeEntityManager(entityManager);
  }
  return summary;
}

Fixed version (ground truth):
public RatingSummaryVo getCommentRatingSummary(long commentId){
  EntityManager entityManager=null;
  RatingSummaryVo summary=null;
  try {
    entityManager=getEntityManagerFactory().createEntityManager();
    summary=getServiceFactory().getCommentRatingService().getSummary(entityManager,commentId);
  }
 catch (  Exception exception) {
    getServiceFactory().getLogService().error(exception.getMessage(),exception);
    FacadesHelper.closeEntityManager(entityManager);
    throw new RuntimeException(exception);
  }
 finally {
    FacadesHelper.closeEntityManager(entityManager);
  }
  return summary;
}
Program: 98493
Project: 98493
Buggy source:
public List<CommentVo> getLastComments(int maxResults){
  EntityManager entityManager=null;
  List<CommentVo> commentVos;
  try {
    entityManager=getEntityManagerFactory().createEntityManager();
    commentVos=getServiceFactory().getCommentsService().getLastComments(entityManager,maxResults);
  }
 catch (  Exception exception) {
    getServiceFactory().getLogService().error(exception.getMessage(),exception);
    throw new RuntimeException(exception);
  }
 finally {
    FacadesHelper.closeEntityManager(entityManager);
  }
  return commentVos;
}

Fixed version (ground truth):
public List<CommentVo> getLastComments(int maxResults){
  EntityManager entityManager=null;
  List<CommentVo> commentVos;
  try {
    entityManager=getEntityManagerFactory().createEntityManager();
    commentVos=getServiceFactory().getCommentsService().getLastComments(entityManager,maxResults);
  }
 catch (  Exception exception) {
    getServiceFactory().getLogService().error(exception.getMessage(),exception);
    FacadesHelper.closeEntityManager(entityManager);
    throw new RuntimeException(exception);
  }
 finally {
    FacadesHelper.closeEntityManager(entityManager);
  }
  return commentVos;
}
Program: 98494
Project: 98494
Buggy source:
public CourseVo createCourse(long professorId,long subjectId,long periodId) throws MultipleMessagesException, DuplicityException {
  CourseVo courseVo=null;
  EntityManager entityManager=null;
  EntityTransaction transaction=null;
  try {
    courseVo=new CourseVo();
    courseVo.setPeriodId(periodId);
    courseVo.setProfessorId(professorId);
    courseVo.setSubjectId(subjectId);
    courseVo.setRatingCount(0L);
    courseVo.setRatingAverage(0.0);
    entityManager=getEntityManagerFactory().createEntityManager();
    transaction=entityManager.getTransaction();
    transaction.begin();
    courseVo=getServiceFactory().getCoursesService().create(entityManager,courseVo);
    transaction.commit();
  }
 catch (  Exception exception) {
    getServiceFactory().getLogService().error(exception.getMessage(),exception);
    FacadesHelper.checkException(exception,MultipleMessagesException.class);
    FacadesHelper.checkDuplicityViolation(entityManager,transaction,exception);
    FacadesHelper.rollbackTransaction(entityManager,transaction,exception);
  }
 finally {
    FacadesHelper.closeEntityManager(entityManager);
  }
  return courseVo;
}

Fixed version (ground truth):
public CourseVo createCourse(long professorId,long subjectId,long periodId) throws MultipleMessagesException, DuplicityException {
  CourseVo courseVo=null;
  EntityManager entityManager=null;
  EntityTransaction transaction=null;
  try {
    courseVo=new CourseVo();
    courseVo.setPeriodId(periodId);
    courseVo.setProfessorId(professorId);
    courseVo.setSubjectId(subjectId);
    courseVo.setRatingCount(0L);
    courseVo.setRatingAverage(0.0);
    entityManager=getEntityManagerFactory().createEntityManager();
    transaction=entityManager.getTransaction();
    transaction.begin();
    courseVo=getServiceFactory().getCoursesService().create(entityManager,courseVo);
    transaction.commit();
  }
 catch (  Exception exception) {
    getServiceFactory().getLogService().error(exception.getMessage(),exception);
    FacadesHelper.checkException(entityManager,exception,MultipleMessagesException.class);
    FacadesHelper.checkDuplicityViolation(entityManager,transaction,exception);
    FacadesHelper.rollbackTransactionAndCloseEntityManager(entityManager,transaction,exception);
  }
 finally {
    FacadesHelper.closeEntityManager(entityManager);
  }
  return courseVo;
}
Program: 98495
Project: 98495
Buggy source:
/** 
 * Searches for courses by professor and subject name that contain the string specified in the query parameter. If the query is empty or full of spaces, the results will be empty. (Because of the overhead of bringing ALL the information from database and translating it to the proper format).
 * @param query String to be searched among the professors and subjectsnames.
 * @return A list of CourseVoVwFull with the information of the foundcourses.
 */
public List<Long> search(String query,int totalHints){
  EntityManager entityManager=null;
  List<Long> resultList=new ArrayList<Long>();
  if (query != null && !query.isEmpty()) {
    try {
      entityManager=getEntityManagerFactory().createEntityManager();
      getServiceFactory().getCoursesService().setSearch(SearchBehaviorFactory.getCourseSearch());
      resultList=getServiceFactory().getCoursesService().search(query,totalHints);
      if (!resultList.isEmpty()) {
        return resultList;
      }
      getServiceFactory().getCoursesService().setSearch(SearchBehaviorFactory.getFuzzyCourseSearch());
      return getServiceFactory().getCoursesService().search(query,totalHints);
    }
 catch (    Exception e) {
      getServiceFactory().getLogService().error(e.getMessage(),e);
      throw new RuntimeException(e);
    }
 finally {
      FacadesHelper.closeEntityManager(entityManager);
    }
  }
  return resultList;
}

Fixed version (ground truth):
/** 
 * Searches for courses by professor and subject name that contain the string specified in the query parameter. If the query is empty or full of spaces, the results will be empty. (Because of the overhead of bringing ALL the information from database and translating it to the proper format).
 * @param query String to be searched among the professors and subjectsnames.
 * @return A list of CourseVoVwFull with the information of the foundcourses.
 */
public List<Long> search(String query,int totalHints){
  List<Long> resultList=new ArrayList<Long>();
  if (query != null && !query.isEmpty()) {
    try {
      getServiceFactory().getCoursesService().setSearch(SearchBehaviorFactory.getCourseSearch());
      resultList=getServiceFactory().getCoursesService().search(query,totalHints);
      if (!resultList.isEmpty()) {
        return resultList;
      }
      getServiceFactory().getCoursesService().setSearch(SearchBehaviorFactory.getFuzzyCourseSearch());
      return getServiceFactory().getCoursesService().search(query,totalHints);
    }
 catch (    Exception e) {
      getServiceFactory().getLogService().error(e.getMessage(),e);
      throw new RuntimeException(e);
    }
  }
  return resultList;
}
Program: 98496
Project: 98496
Buggy source:
public CourseRatingVo getCourseRatingByUserId(long courseId,long userId){
  EntityManager entityManager=null;
  CourseRatingVo courseRatingVo=null;
  try {
    entityManager=getEntityManagerFactory().createEntityManager();
    courseRatingVo=getServiceFactory().getCourseRatingsService().getByCourseIdAndUserId(entityManager,courseId,userId);
  }
 catch (  Exception exception) {
    getServiceFactory().getLogService().error(exception.getMessage(),exception);
    throw new RuntimeException(exception);
  }
 finally {
    FacadesHelper.closeEntityManager(entityManager);
  }
  return courseRatingVo;
}

Fixed version (ground truth):
public CourseRatingVo getCourseRatingByUserId(long courseId,long userId){
  EntityManager entityManager=null;
  CourseRatingVo courseRatingVo=null;
  try {
    entityManager=getEntityManagerFactory().createEntityManager();
    courseRatingVo=getServiceFactory().getCourseRatingsService().getByCourseIdAndUserId(entityManager,courseId,userId);
  }
 catch (  Exception exception) {
    getServiceFactory().getLogService().error(exception.getMessage(),exception);
    FacadesHelper.closeEntityManager(entityManager);
    throw new RuntimeException(exception);
  }
 finally {
    FacadesHelper.closeEntityManager(entityManager);
  }
  return courseRatingVo;
}
Program: 98497
Project: 98497
Buggy source:
public void deleteCourse(long courseId) throws DataBaseException {
  EntityManager entityManager=null;
  EntityTransaction transaction=null;
  try {
    entityManager=getEntityManagerFactory().createEntityManager();
    transaction=entityManager.getTransaction();
    transaction.begin();
    getServiceFactory().getCoursesService().delete(entityManager,courseId);
    transaction.commit();
  }
 catch (  Exception exception) {
    getServiceFactory().getLogService().error(exception.getMessage(),exception);
    FacadesHelper.checkExceptionAndRollback(entityManager,transaction,exception,DataBaseException.class);
    FacadesHelper.rollbackTransaction(entityManager,transaction,exception);
  }
 finally {
    FacadesHelper.closeEntityManager(entityManager);
  }
}

Fixed version (ground truth):
public void deleteCourse(long courseId) throws DataBaseException {
  EntityManager entityManager=null;
  EntityTransaction transaction=null;
  try {
    entityManager=getEntityManagerFactory().createEntityManager();
    transaction=entityManager.getTransaction();
    transaction.begin();
    getServiceFactory().getCoursesService().delete(entityManager,courseId);
    transaction.commit();
  }
 catch (  Exception exception) {
    getServiceFactory().getLogService().error(exception.getMessage(),exception);
    FacadesHelper.checkExceptionAndRollback(entityManager,transaction,exception,DataBaseException.class);
    FacadesHelper.rollbackTransactionAndCloseEntityManager(entityManager,transaction,exception);
  }
 finally {
    FacadesHelper.closeEntityManager(entityManager);
  }
}
Program: 98498
Project: 98498
Buggy source:
/** 
 * @param professorId
 * @return If there is no professor associated with the provided id an emptylist will be returned
 */
public List<CourseVoFull> getByProfessorId(long professorId){
  EntityManager entityManager=null;
  List<CourseVoFull> coursesList=new ArrayList<CourseVoFull>();
  HashMap<Long,SubjectVo> subjectsVo=new HashMap<Long,SubjectVo>();
  try {
    entityManager=getEntityManagerFactory().createEntityManager();
    List<CourseVo> courses=getServiceFactory().getCoursesService().getByProfessorId(entityManager,professorId);
    ProfessorVo professorVo=getServiceFactory().getProfessorsService().read(entityManager,professorId);
    for (    CourseVo courseVo : courses) {
      if (!subjectsVo.containsKey(courseVo.getSubjectId())) {
        SubjectVo subjectVo=getServiceFactory().getSubjectsService().read(entityManager,courseVo.getSubjectId());
        subjectsVo.put(subjectVo.getId(),subjectVo);
      }
      coursesList.add(new CourseVoFull(courseVo,subjectsVo.get(courseVo.getSubjectId()),professorVo));
    }
  }
 catch (  Exception exception) {
    getServiceFactory().getLogService().error(exception.getMessage(),exception);
    throw new RuntimeException(exception);
  }
 finally {
    FacadesHelper.closeEntityManager(entityManager);
  }
  return coursesList;
}

Fixed version (ground truth):
/** 
 * @param professorId
 * @return If there is no professor associated with the provided id an emptylist will be returned
 */
public List<CourseVoFull> getByProfessorId(long professorId){
  EntityManager entityManager=null;
  List<CourseVoFull> coursesList=new ArrayList<CourseVoFull>();
  HashMap<Long,SubjectVo> subjectsVo=new HashMap<Long,SubjectVo>();
  try {
    entityManager=getEntityManagerFactory().createEntityManager();
    List<CourseVo> courses=getServiceFactory().getCoursesService().getByProfessorId(entityManager,professorId);
    ProfessorVo professorVo=getServiceFactory().getProfessorsService().read(entityManager,professorId);
    for (    CourseVo courseVo : courses) {
      if (!subjectsVo.containsKey(courseVo.getSubjectId())) {
        SubjectVo subjectVo=getServiceFactory().getSubjectsService().read(entityManager,courseVo.getSubjectId());
        subjectsVo.put(subjectVo.getId(),subjectVo);
      }
      coursesList.add(new CourseVoFull(courseVo,subjectsVo.get(courseVo.getSubjectId()),professorVo));
    }
  }
 catch (  Exception exception) {
    getServiceFactory().getLogService().error(exception.getMessage(),exception);
    FacadesHelper.closeEntityManager(entityManager);
    throw new RuntimeException(exception);
  }
 finally {
    FacadesHelper.closeEntityManager(entityManager);
  }
  return coursesList;
}
Program: 98499
Project: 98499
Buggy source:
public List<CourseVoFull> getSimilarCourses(String professorName,String subjectName,Long periodId){
  EntityManager entityManager=null;
  List<CourseVoFull> courseVoFulls=new ArrayList<CourseVoFull>();
  HashMap<Long,ProfessorVo> professorsVos=new HashMap<Long,ProfessorVo>();
  HashMap<Long,SubjectVo> subjectsVos=new HashMap<Long,SubjectVo>();
  try {
    entityManager=getEntityManagerFactory().createEntityManager();
    List<CourseVo> similarCourses=getServiceFactory().getCoursesService().getSimilarCourses(entityManager,professorName,subjectName,periodId);
    for (    CourseVo courseVo : similarCourses) {
      if (!professorsVos.containsKey(courseVo.getProfessorId())) {
        ProfessorVo professorVo=getServiceFactory().getProfessorsService().read(entityManager,courseVo.getProfessorId());
        professorsVos.put(professorVo.getId(),professorVo);
      }
      if (!subjectsVos.containsKey(courseVo.getSubjectId())) {
        SubjectVo subjectVo=getServiceFactory().getSubjectsService().read(entityManager,courseVo.getSubjectId());
        subjectsVos.put(subjectVo.getId(),subjectVo);
      }
      courseVoFulls.add(new CourseVoFull(courseVo,subjectsVos.get(courseVo.getSubjectId()),professorsVos.get(courseVo.getProfessorId())));
    }
  }
 catch (  Exception exception) {
    getServiceFactory().getLogService().error(exception.getMessage(),exception);
    throw new RuntimeException(exception);
  }
 finally {
    FacadesHelper.closeEntityManager(entityManager);
  }
  return courseVoFulls;
}

Fixed version (ground truth):
public List<CourseVoFull> getSimilarCourses(String professorName,String subjectName,Long periodId){
  EntityManager entityManager=null;
  List<CourseVoFull> courseVoFulls=new ArrayList<CourseVoFull>();
  HashMap<Long,ProfessorVo> professorsVos=new HashMap<Long,ProfessorVo>();
  HashMap<Long,SubjectVo> subjectsVos=new HashMap<Long,SubjectVo>();
  try {
    entityManager=getEntityManagerFactory().createEntityManager();
    List<CourseVo> similarCourses=getServiceFactory().getCoursesService().getSimilarCourses(entityManager,professorName,subjectName,periodId);
    for (    CourseVo courseVo : similarCourses) {
      if (!professorsVos.containsKey(courseVo.getProfessorId())) {
        ProfessorVo professorVo=getServiceFactory().getProfessorsService().read(entityManager,courseVo.getProfessorId());
        professorsVos.put(professorVo.getId(),professorVo);
      }
      if (!subjectsVos.containsKey(courseVo.getSubjectId())) {
        SubjectVo subjectVo=getServiceFactory().getSubjectsService().read(entityManager,courseVo.getSubjectId());
        subjectsVos.put(subjectVo.getId(),subjectVo);
      }
      courseVoFulls.add(new CourseVoFull(courseVo,subjectsVos.get(courseVo.getSubjectId()),professorsVos.get(courseVo.getProfessorId())));
    }
  }
 catch (  Exception exception) {
    getServiceFactory().getLogService().error(exception.getMessage(),exception);
    FacadesHelper.closeEntityManager(entityManager);
    throw new RuntimeException(exception);
  }
 finally {
    FacadesHelper.closeEntityManager(entityManager);
  }
  return courseVoFulls;
}
Program: 98500
Project: 98500
Buggy source:
public CourseVoFull getCourse(long courseId){
  EntityManager entityManager=null;
  CourseVoFull courseVoFull=null;
  try {
    entityManager=getEntityManagerFactory().createEntityManager();
    CourseVo vo=getServiceFactory().getCoursesService().read(entityManager,courseId);
    if (vo == null) {
      return null;
    }
    SubjectVo subjectVo=getServiceFactory().getSubjectsService().read(entityManager,vo.getSubjectId());
    ProfessorVo professorVo=getServiceFactory().getProfessorsService().read(entityManager,vo.getProfessorId());
    courseVoFull=new CourseVoFull(vo,subjectVo,professorVo);
  }
 catch (  Exception e) {
    getServiceFactory().getLogService().error(e.getMessage(),e);
    throw new RuntimeException(e);
  }
 finally {
    FacadesHelper.closeEntityManager(entityManager);
  }
  return courseVoFull;
}

Fixed version (ground truth):
public CourseVoFull getCourse(long courseId){
  EntityManager entityManager=null;
  CourseVoFull courseVoFull=null;
  try {
    entityManager=getEntityManagerFactory().createEntityManager();
    CourseVo vo=getServiceFactory().getCoursesService().read(entityManager,courseId);
    if (vo == null) {
      return null;
    }
    SubjectVo subjectVo=getServiceFactory().getSubjectsService().read(entityManager,vo.getSubjectId());
    ProfessorVo professorVo=getServiceFactory().getProfessorsService().read(entityManager,vo.getProfessorId());
    courseVoFull=new CourseVoFull(vo,subjectVo,professorVo);
  }
 catch (  Exception e) {
    getServiceFactory().getLogService().error(e.getMessage(),e);
    FacadesHelper.closeEntityManager(entityManager);
    throw new RuntimeException(e);
  }
 finally {
    FacadesHelper.closeEntityManager(entityManager);
  }
  return courseVoFull;
}
Program: 98502
Project: 98502
Buggy source:
public List<CourseVoFull> getBySubjectId(long subjectId){
  EntityManager entityManager=null;
  List<CourseVoFull> courseVoFulls=new ArrayList<CourseVoFull>();
  HashMap<Long,ProfessorVo> professorsVo=new HashMap<Long,ProfessorVo>();
  try {
    entityManager=getEntityManagerFactory().createEntityManager();
    List<CourseVo> courseVos=getServiceFactory().getCoursesService().getBySubjectId(entityManager,subjectId);
    SubjectVo subjectVo=getServiceFactory().getSubjectsService().read(entityManager,subjectId);
    for (    CourseVo courseVo : courseVos) {
      if (!professorsVo.containsKey(courseVo.getProfessorId())) {
        ProfessorVo professorVo=getServiceFactory().getProfessorsService().read(entityManager,courseVo.getProfessorId());
        professorsVo.put(professorVo.getId(),professorVo);
      }
      courseVoFulls.add(new CourseVoFull(courseVo,subjectVo,professorsVo.get(courseVo.getProfessorId())));
    }
  }
 catch (  Exception exception) {
    getServiceFactory().getLogService().error(exception.getMessage(),exception);
    throw new RuntimeException(exception);
  }
 finally {
    FacadesHelper.closeEntityManager(entityManager);
  }
  return courseVoFulls;
}

Fixed version (ground truth):
public List<CourseVoFull> getBySubjectId(long subjectId){
  EntityManager entityManager=null;
  List<CourseVoFull> courseVoFulls=new ArrayList<CourseVoFull>();
  HashMap<Long,ProfessorVo> professorsVo=new HashMap<Long,ProfessorVo>();
  try {
    entityManager=getEntityManagerFactory().createEntityManager();
    List<CourseVo> courseVos=getServiceFactory().getCoursesService().getBySubjectId(entityManager,subjectId);
    SubjectVo subjectVo=getServiceFactory().getSubjectsService().read(entityManager,subjectId);
    for (    CourseVo courseVo : courseVos) {
      if (!professorsVo.containsKey(courseVo.getProfessorId())) {
        ProfessorVo professorVo=getServiceFactory().getProfessorsService().read(entityManager,courseVo.getProfessorId());
        professorsVo.put(professorVo.getId(),professorVo);
      }
      courseVoFulls.add(new CourseVoFull(courseVo,subjectVo,professorsVo.get(courseVo.getProfessorId())));
    }
  }
 catch (  Exception exception) {
    getServiceFactory().getLogService().error(exception.getMessage(),exception);
    FacadesHelper.closeEntityManager(entityManager);
    throw new RuntimeException(exception);
  }
 finally {
    FacadesHelper.closeEntityManager(entityManager);
  }
  return courseVoFulls;
}
Program: 98503
Project: 98503
Buggy source:
public List<FeedbackVo> getAllFeedbacks(int firstResult,int maxResults){
  List<FeedbackVo> list=null;
  EntityManager em=null;
  try {
    em=getEntityManagerFactory().createEntityManager();
    list=getServiceFactory().getFeedbacksService().getAllFeedbacks(em,firstResult,maxResults);
  }
 catch (  Exception ex) {
    getServiceFactory().getLogService().error(ex.getMessage(),ex);
    throw new RuntimeException(ex);
  }
 finally {
    FacadesHelper.closeEntityManager(em);
  }
  return list;
}

Fixed version (ground truth):
public List<FeedbackVo> getAllFeedbacks(int firstResult,int maxResults){
  List<FeedbackVo> list=null;
  EntityManager entityManager=null;
  try {
    entityManager=getEntityManagerFactory().createEntityManager();
    list=getServiceFactory().getFeedbacksService().getAllFeedbacks(entityManager,firstResult,maxResults);
  }
 catch (  Exception ex) {
    getServiceFactory().getLogService().error(ex.getMessage(),ex);
    FacadesHelper.closeEntityManager(entityManager);
    throw new RuntimeException(ex);
  }
 finally {
    FacadesHelper.closeEntityManager(entityManager);
  }
  return list;
}
Program: 98504
Project: 98504
Buggy source:
public FeedbackTypeVo getFeedbackType(long feedbackTypeId){
  EntityManager em=null;
  try {
    em=getEntityManagerFactory().createEntityManager();
    return getServiceFactory().getFeedbackTypesService().read(em,feedbackTypeId);
  }
 catch (  Exception ex) {
    getServiceFactory().getLogService().error(ex.getMessage(),ex);
    throw new RuntimeException(ex);
  }
 finally {
    FacadesHelper.closeEntityManager(em);
  }
}

Fixed version (ground truth):
public FeedbackTypeVo getFeedbackType(long feedbackTypeId){
  EntityManager entityManager=null;
  try {
    entityManager=getEntityManagerFactory().createEntityManager();
    return getServiceFactory().getFeedbackTypesService().read(entityManager,feedbackTypeId);
  }
 catch (  Exception ex) {
    getServiceFactory().getLogService().error(ex.getMessage(),ex);
    FacadesHelper.closeEntityManager(entityManager);
    throw new RuntimeException(ex);
  }
 finally {
    FacadesHelper.closeEntityManager(entityManager);
  }
}
Program: 98505
Project: 98505
Buggy source:
public FeedbackVo createFeedback(long feedbackType,String feedbackcontent,Date date) throws MultipleMessagesException, DuplicityException {
  FeedbackVo feedbackVo=new FeedbackVo();
  feedbackVo.setContent(feedbackcontent);
  feedbackVo.setDate(date);
  feedbackVo.setFeedbackTypeId(feedbackType);
  EntityManager entityManager=null;
  EntityTransaction transaction=null;
  try {
    entityManager=getEntityManagerFactory().createEntityManager();
    transaction=entityManager.getTransaction();
    transaction.begin();
    feedbackVo=getServiceFactory().getFeedbacksService().create(entityManager,feedbackVo);
    transaction.commit();
  }
 catch (  Exception exception) {
    getServiceFactory().getLogService().error(exception.getMessage(),exception);
    FacadesHelper.checkException(exception,MultipleMessagesException.class);
    FacadesHelper.checkDuplicityViolation(entityManager,transaction,exception);
    FacadesHelper.rollbackTransaction(entityManager,transaction,exception);
  }
 finally {
    FacadesHelper.closeEntityManager(entityManager);
  }
  return feedbackVo;
}

Fixed version (ground truth):
public FeedbackVo createFeedback(long feedbackType,String feedbackcontent,Date date) throws MultipleMessagesException, DuplicityException {
  FeedbackVo feedbackVo=new FeedbackVo();
  feedbackVo.setContent(feedbackcontent);
  feedbackVo.setDate(date);
  feedbackVo.setFeedbackTypeId(feedbackType);
  EntityManager entityManager=null;
  EntityTransaction transaction=null;
  try {
    entityManager=getEntityManagerFactory().createEntityManager();
    transaction=entityManager.getTransaction();
    transaction.begin();
    feedbackVo=getServiceFactory().getFeedbacksService().create(entityManager,feedbackVo);
    transaction.commit();
  }
 catch (  Exception exception) {
    getServiceFactory().getLogService().error(exception.getMessage(),exception);
    FacadesHelper.checkException(entityManager,exception,MultipleMessagesException.class);
    FacadesHelper.checkDuplicityViolation(entityManager,transaction,exception);
    FacadesHelper.rollbackTransactionAndCloseEntityManager(entityManager,transaction,exception);
  }
 finally {
    FacadesHelper.closeEntityManager(entityManager);
  }
  return feedbackVo;
}
Program: 98506
Project: 98506
Buggy source:
public long countAllFeedbacks(){
  EntityManager em=null;
  try {
    em=getEntityManagerFactory().createEntityManager();
    return getServiceFactory().getFeedbacksService().countAllFeedbacks(em);
  }
 catch (  Exception ex) {
    getServiceFactory().getLogService().error(ex.getMessage(),ex);
    throw new RuntimeException(ex);
  }
 finally {
    FacadesHelper.closeEntityManager(em);
  }
}

Fixed version (ground truth):
public long countAllFeedbacks(){
  EntityManager entityManager=null;
  try {
    entityManager=getEntityManagerFactory().createEntityManager();
    return getServiceFactory().getFeedbacksService().countAllFeedbacks(entityManager);
  }
 catch (  Exception ex) {
    getServiceFactory().getLogService().error(ex.getMessage(),ex);
    FacadesHelper.closeEntityManager(entityManager);
    throw new RuntimeException(ex);
  }
 finally {
    FacadesHelper.closeEntityManager(entityManager);
  }
}
Program: 98507
Project: 98507
Buggy source:
public List<FeedbackVo> getFeedbacksByFeedbackType(long feedbackTypeId,int firstResult,int maxResults){
  List<FeedbackVo> feedbackVos=null;
  EntityManager entityManager=null;
  try {
    entityManager=getEntityManagerFactory().createEntityManager();
    feedbackVos=getServiceFactory().getFeedbacksService().getFeedbacksByFeedbackType(entityManager,feedbackTypeId,firstResult,maxResults);
  }
 catch (  Exception exception) {
    getServiceFactory().getLogService().error(exception.getMessage(),exception);
    throw new RuntimeException(exception);
  }
 finally {
    FacadesHelper.closeEntityManager(entityManager);
  }
  return feedbackVos;
}

Fixed version (ground truth):
public List<FeedbackVo> getFeedbacksByFeedbackType(long feedbackTypeId,int firstResult,int maxResults){
  List<FeedbackVo> feedbackVos=null;
  EntityManager entityManager=null;
  try {
    entityManager=getEntityManagerFactory().createEntityManager();
    feedbackVos=getServiceFactory().getFeedbacksService().getFeedbacksByFeedbackType(entityManager,feedbackTypeId,firstResult,maxResults);
  }
 catch (  Exception exception) {
    getServiceFactory().getLogService().error(exception.getMessage(),exception);
    FacadesHelper.closeEntityManager(entityManager);
    throw new RuntimeException(exception);
  }
 finally {
    FacadesHelper.closeEntityManager(entityManager);
  }
  return feedbackVos;
}
Program: 98508
Project: 98508
Buggy source:
public long countFeedbacksByFeedbackType(long feedbackTypeId){
  EntityManager em=null;
  try {
    em=getEntityManagerFactory().createEntityManager();
    return getServiceFactory().getFeedbacksService().countFeedbacksByTypeId(em,feedbackTypeId);
  }
 catch (  Exception ex) {
    getServiceFactory().getLogService().error(ex.getMessage(),ex);
    throw new RuntimeException(ex);
  }
 finally {
    FacadesHelper.closeEntityManager(em);
  }
}

Fixed version (ground truth):
public long countFeedbacksByFeedbackType(long feedbackTypeId){
  EntityManager entityManager=null;
  try {
    entityManager=getEntityManagerFactory().createEntityManager();
    return getServiceFactory().getFeedbacksService().countFeedbacksByTypeId(entityManager,feedbackTypeId);
  }
 catch (  Exception ex) {
    getServiceFactory().getLogService().error(ex.getMessage(),ex);
    FacadesHelper.closeEntityManager(entityManager);
    throw new RuntimeException(ex);
  }
 finally {
    FacadesHelper.closeEntityManager(entityManager);
  }
}
Program: 98509
Project: 98509
Buggy source:
public List<FeedbackTypeVo> getFeedbackTypes(){
  List<FeedbackTypeVo> feedbackTypeVos=null;
  EntityManager entityManager=null;
  try {
    entityManager=getEntityManagerFactory().createEntityManager();
    feedbackTypeVos=getServiceFactory().getFeedbackTypesService().list(entityManager);
  }
 catch (  Exception exception) {
    getServiceFactory().getLogService().error(exception.getMessage(),exception);
    throw new RuntimeException(exception);
  }
 finally {
    FacadesHelper.closeEntityManager(entityManager);
  }
  return feedbackTypeVos;
}

Fixed version (ground truth):
public List<FeedbackTypeVo> getFeedbackTypes(){
  List<FeedbackTypeVo> feedbackTypeVos=null;
  EntityManager entityManager=null;
  try {
    entityManager=getEntityManagerFactory().createEntityManager();
    feedbackTypeVos=getServiceFactory().getFeedbackTypesService().list(entityManager);
  }
 catch (  Exception exception) {
    getServiceFactory().getLogService().error(exception.getMessage(),exception);
    FacadesHelper.closeEntityManager(entityManager);
    throw new RuntimeException(exception);
  }
 finally {
    FacadesHelper.closeEntityManager(entityManager);
  }
  return feedbackTypeVos;
}
Program: 98510
Project: 98510
Buggy source:
public List<PeriodVo> listPeriods(){
  List<PeriodVo> periodVos;
  EntityManager entityManager=null;
  try {
    entityManager=getEntityManagerFactory().createEntityManager();
    periodVos=getServiceFactory().getPeriodsService().list(entityManager);
  }
 catch (  Exception enException) {
    getServiceFactory().getLogService().error(enException.getMessage(),enException);
    throw new RuntimeException(enException);
  }
 finally {
    FacadesHelper.closeEntityManager(entityManager);
  }
  return periodVos;
}

Fixed version (ground truth):
public List<PeriodVo> listPeriods(){
  List<PeriodVo> periodVos;
  EntityManager entityManager=null;
  try {
    entityManager=getEntityManagerFactory().createEntityManager();
    periodVos=getServiceFactory().getPeriodsService().list(entityManager);
  }
 catch (  Exception enException) {
    getServiceFactory().getLogService().error(enException.getMessage(),enException);
    FacadesHelper.closeEntityManager(entityManager);
    throw new RuntimeException(enException);
  }
 finally {
    FacadesHelper.closeEntityManager(entityManager);
  }
  return periodVos;
}
Program: 98511
Project: 98511
Buggy source:
/** 
 * Persist a new Period with the specified year and semester.
 * @param em entity manager
 * @param year
 * @param semester
 * @return Returns null if there is a problem while persisting (logs allerrors) and throws an exception if data isn't valid.
 */
public PeriodVo createPeriod(int year,int semester) throws MultipleMessagesException, DataBaseException, DuplicityException {
  PeriodVo periodVo=new PeriodVo();
  periodVo.setYear(year);
  periodVo.setSemester(semester);
  EntityManager entityManager=null;
  EntityTransaction transaction=null;
  try {
    entityManager=getEntityManagerFactory().createEntityManager();
    transaction=entityManager.getTransaction();
    transaction.begin();
    periodVo=getServiceFactory().getPeriodsService().create(entityManager,periodVo);
    transaction.commit();
  }
 catch (  Exception exception) {
    getServiceFactory().getLogService().error(exception.getMessage(),exception);
    FacadesHelper.checkException(exception,MultipleMessagesException.class);
    FacadesHelper.checkDuplicityViolation(entityManager,transaction,exception);
    FacadesHelper.rollbackTransaction(entityManager,transaction,exception);
  }
 finally {
    FacadesHelper.closeEntityManager(entityManager);
  }
  return periodVo;
}

Fixed version (ground truth):
/** 
 * Persist a new Period with the specified year and semester.
 * @param em entity manager
 * @param year
 * @param semester
 * @return Returns null if there is a problem while persisting (logs allerrors) and throws an exception if data isn't valid.
 */
public PeriodVo createPeriod(int year,int semester) throws MultipleMessagesException, DataBaseException, DuplicityException {
  PeriodVo periodVo=new PeriodVo();
  periodVo.setYear(year);
  periodVo.setSemester(semester);
  EntityManager entityManager=null;
  EntityTransaction transaction=null;
  try {
    entityManager=getEntityManagerFactory().createEntityManager();
    transaction=entityManager.getTransaction();
    transaction.begin();
    periodVo=getServiceFactory().getPeriodsService().create(entityManager,periodVo);
    transaction.commit();
  }
 catch (  Exception exception) {
    getServiceFactory().getLogService().error(exception.getMessage(),exception);
    FacadesHelper.checkException(entityManager,exception,MultipleMessagesException.class);
    FacadesHelper.checkDuplicityViolation(entityManager,transaction,exception);
    FacadesHelper.rollbackTransactionAndCloseEntityManager(entityManager,transaction,exception);
  }
 finally {
    FacadesHelper.closeEntityManager(entityManager);
  }
  return periodVo;
}
Program: 98512
Project: 98512
Buggy source:
public void deletePeriod(long periodId) throws DataBaseException {
  EntityManager entityManager=null;
  EntityTransaction transaction=null;
  try {
    entityManager=getEntityManagerFactory().createEntityManager();
    transaction=entityManager.getTransaction();
    transaction.begin();
    getServiceFactory().getPeriodsService().delete(entityManager,periodId);
    transaction.commit();
  }
 catch (  DataBaseException exception) {
    getServiceFactory().getLogService().error(exception.getMessage(),exception);
    FacadesHelper.rollbackTransaction(entityManager,transaction,exception);
  }
 finally {
    FacadesHelper.closeEntityManager(entityManager);
  }
}

Fixed version (ground truth):
public void deletePeriod(long periodId) throws DataBaseException {
  EntityManager entityManager=null;
  EntityTransaction transaction=null;
  try {
    entityManager=getEntityManagerFactory().createEntityManager();
    transaction=entityManager.getTransaction();
    transaction.begin();
    getServiceFactory().getPeriodsService().delete(entityManager,periodId);
    transaction.commit();
  }
 catch (  DataBaseException exception) {
    getServiceFactory().getLogService().error(exception.getMessage(),exception);
    FacadesHelper.rollbackTransactionAndCloseEntityManager(entityManager,transaction,exception);
  }
 finally {
    FacadesHelper.closeEntityManager(entityManager);
  }
}
Program: 98513
Project: 98513
Buggy source:
public PeriodVo getPeriod(long periodId){
  EntityManager entityManager=null;
  PeriodVo period=null;
  try {
    entityManager=getEntityManagerFactory().createEntityManager();
    period=getServiceFactory().getPeriodsService().read(entityManager,periodId);
  }
 catch (  Exception enException) {
    getServiceFactory().getLogService().error(enException.getMessage(),enException);
    throw new RuntimeException(enException);
  }
 finally {
    FacadesHelper.closeEntityManager(entityManager);
  }
  return period;
}

Fixed version (ground truth):
public PeriodVo getPeriod(long periodId){
  EntityManager entityManager=null;
  PeriodVo period=null;
  try {
    entityManager=getEntityManagerFactory().createEntityManager();
    period=getServiceFactory().getPeriodsService().read(entityManager,periodId);
  }
 catch (  Exception enException) {
    getServiceFactory().getLogService().error(enException.getMessage(),enException);
    FacadesHelper.closeEntityManager(entityManager);
    throw new RuntimeException(enException);
  }
 finally {
    FacadesHelper.closeEntityManager(entityManager);
  }
  return period;
}
Program: 98514
Project: 98514
Buggy source:
/** 
 * Searches for courses by professor and subject name that contain the string specified in the query parameter. If the query is empty or full of spaces, the results will be empty. (Because of the overhead of bringing ALL the information from database and translating it to the proper format).
 * @param query String to be searched among the professors and subjectsnames.
 * @return A list of CourseVoVwFull with the information of the foundcourses.
 */
public List<Long> search(String query,int totalHints){
  List<Long> resultList=new ArrayList<Long>();
  if (query != null && !query.isEmpty()) {
    try {
      getServiceFactory().getCoursesService().setSearch(SearchBehaviorFactory.getCourseSearch());
      resultList=getServiceFactory().getCoursesService().search(query,totalHints);
      if (!resultList.isEmpty()) {
        return resultList;
      }
      getServiceFactory().getCoursesService().setSearch(SearchBehaviorFactory.getFuzzyCourseSearch());
      return getServiceFactory().getCoursesService().search(query,totalHints);
    }
 catch (    Exception e) {
      getServiceFactory().getLogService().error(e.getMessage(),e);
      throw new RuntimeException(e);
    }
  }
  return resultList;
}

Fixed version (ground truth):
/** 
 * Searches for courses by professor and subject name that contain the string specified in the query parameter. If the query is empty or full of spaces, the results will be empty. (Because of the overhead of bringing ALL the information from database and translating it to the proper format).
 * @param query String to be searched among the professors and subjectsnames.
 * @return A list of CourseVoVwFull with the information of the foundcourses.
 */
public List<Long> search(String query,int totalHints){
  List<Long> resultList=new ArrayList<Long>();
  if (query != null && !query.isEmpty()) {
    try {
      getServiceFactory().getCoursesService().setSearch(SearchBehaviorFactory.getCourseSearch());
      resultList=getServiceFactory().getCoursesService().search(query,totalHints);
      if (!resultList.isEmpty()) {
        return resultList;
      }
      getServiceFactory().getCoursesService().setSearch(SearchBehaviorFactory.getFuzzyCourseSearch());
      return getServiceFactory().getCoursesService().search(query,totalHints);
    }
 catch (    Exception exception) {
      getServiceFactory().getLogService().error(exception.getMessage(),exception);
      FacadesHelper.checkException(exception,ExternalServiceException.class);
      throw new RuntimeException(exception);
    }
  }
  return resultList;
}
Program: 98515
Project: 98515
Buggy source:
public int getSearchCount(String query,int maxitems){
  return facadeFactory.getCoursesFacade().search(query,maxitems).size();
}

Fixed version (ground truth):
public int getSearchCount(String query,int maxitems){
  return getSearchCourses(query,maxitems).size();
}
Program: 98517
Project: 98517
Buggy source:
@Override public CourseRatingEntity update(EntityManager entityManager,CourseRatingEntity entity) throws DataBaseException {
  CourseRatingEntity existingRating=getDao().read(entityManager,entity.getId());
  if (existingRating != null) {
    CourseDao courseDao=daoBuilder.getCourseDao();
    CourseEntity course=entity.getCourse();
    Long totalRatings=course.getRatingCount();
    Double oldAverageSum=course.getRatingAverage() * totalRatings;
    Double newAverage=(oldAverageSum - existingRating.getValue() + entity.getValue()) / totalRatings;
    course.setRatingAverage(newAverage);
    courseDao.update(entityManager,course);
    return getDao().update(entityManager,entity);
  }
 else {
    return null;
  }
}

Fixed version (ground truth):
@Override public CourseRatingEntity update(EntityManager entityManager,CourseRatingEntity entity) throws DataBaseException {
  CourseRatingEntity existingRating=getDao().read(entityManager,entity.getId());
  if (existingRating != null) {
    CourseDao courseDao=daoBuilder.getCourseDao();
    CourseEntity course=entity.getCourse();
    Long totalRatings=course.getRatingCount();
    Double oldAverageSum=course.getRatingAverage() * totalRatings;
    if (totalRatings == 0) {
      totalRatings=1L;
    }
    Double newAverage=(oldAverageSum - existingRating.getValue() + entity.getValue()) / totalRatings;
    if (newAverage < 0) {
      newAverage=(double)entity.getValue();
    }
    course.setRatingAverage(newAverage);
    courseDao.update(entityManager,course);
    return getDao().update(entityManager,entity);
  }
 else {
    return null;
  }
}
Program: 98518
Project: 98518
Buggy source:
public void voteNegativeComment(CommentVoVwFull comment){
switch (rateComment(comment,-1)) {
case -1:
    comment.getRating().setPositive(comment.getRating().getPositive() - 1);
case 1:
  comment.getRating().setNegative(comment.getRating().getNegative() + 1);
break;
case 2:
comment.getRating().setNegative(comment.getRating().getNegative() - 1);
break;
}
}

Fixed version (ground truth):
public void voteNegativeComment(CommentVoVwFull comment){
switch (rateComment(comment,-1)) {
case FROM_OPPOSED:
    comment.getRating().setPositive(comment.getRating().getPositive() - 1);
case FROM_NEUTRAL:
  comment.getRating().setNegative(comment.getRating().getNegative() + 1);
break;
case TO_NEUTRAL:
comment.getRating().setNegative(comment.getRating().getNegative() - 1);
break;
}
}
Program: 98519
Project: 98519
Buggy source:
public void votePositiveComment(CommentVoVwFull comment) throws DataBaseException {
switch (rateComment(comment,1)) {
case -1:
    comment.getRating().setNegative(comment.getRating().getNegative() - 1);
case 1:
  comment.getRating().setPositive(comment.getRating().getPositive() + 1);
break;
case 2:
comment.getRating().setPositive(comment.getRating().getPositive() - 1);
break;
}
}

Fixed version (ground truth):
public void votePositiveComment(CommentVoVwFull comment) throws DataBaseException {
switch (rateComment(comment,1)) {
case FROM_OPPOSED:
    comment.getRating().setNegative(comment.getRating().getNegative() - 1);
case FROM_NEUTRAL:
  comment.getRating().setPositive(comment.getRating().getPositive() + 1);
break;
case TO_NEUTRAL:
comment.getRating().setPositive(comment.getRating().getPositive() - 1);
break;
}
}