Program: 15659
Project: 15659
Buggy source:
/** 
 * Search articles.
 * @param query Search query
 * @return List of articles
 * @throws Exception 
 */
public PaginatedList<UserArticleDto> searchArticles(String userId,List<String> feedList,String searchQuery,Integer offset,Integer limit) throws Exception {
  ArticleDao articleDao=new ArticleDao();
  PaginatedList<UserArticleDto> paginatedList=PaginatedLists.create(limit,offset);
  Map<String,Article> articleMap=null;
  if (feedList.size() > 0) {
    articleMap=articleDao.search(paginatedList,feedList,searchQuery);
  }
  if (articleMap != null && articleMap.size() > 0) {
    UserArticleCriteria userArticleCriteria=new UserArticleCriteria();
    userArticleCriteria.setUserId(userId);
    userArticleCriteria.setVisible(true);
    userArticleCriteria.setArticleIdIn(Lists.newArrayList(articleMap.keySet()));
    UserArticleDao userArticleDao=new UserArticleDao();
    PaginatedList<UserArticleDto> userArticledList=PaginatedLists.create(paginatedList.getLimit(),0);
    userArticleDao.findByCriteria(userArticleCriteria,userArticledList);
    paginatedList.setResultList(userArticledList.getResultList());
    for (    UserArticleDto userArticleDto : paginatedList.getResultList()) {
      Article article=articleMap.get(userArticleDto.getArticleId());
      if (article.getTitle() != null) {
        userArticleDto.setArticleTitle(article.getTitle());
      }
      if (article.getDescription() != null) {
        userArticleDto.setArticleDescription(article.getDescription());
      }
    }
  }
 else {
    paginatedList.setResultList(new ArrayList<UserArticleDto>());
  }
  return paginatedList;
}

Fixed version (ground truth):
/** 
 * Search articles.
 * @param query Search query
 * @return List of articles
 * @throws Exception 
 */
public PaginatedList<UserArticleDto> searchArticles(String userId,List<String> feedList,String searchQuery,Integer offset,Integer limit) throws Exception {
  ArticleDao articleDao=new ArticleDao();
  PaginatedList<UserArticleDto> paginatedList=PaginatedLists.create(limit,offset);
  Map<String,Article> articleMap=null;
  if (feedList.size() > 0) {
    articleMap=articleDao.search(paginatedList,feedList,searchQuery);
  }
  if (articleMap != null && articleMap.size() > 0) {
    UserArticleCriteria userArticleCriteria=new UserArticleCriteria();
    userArticleCriteria.setUserId(userId);
    userArticleCriteria.setVisible(false);
    userArticleCriteria.setArticleIdIn(Lists.newArrayList(articleMap.keySet()));
    UserArticleDao userArticleDao=new UserArticleDao();
    PaginatedList<UserArticleDto> userArticledList=PaginatedLists.create(paginatedList.getLimit(),0);
    userArticleDao.findByCriteria(userArticleCriteria,userArticledList);
    paginatedList.setResultList(userArticledList.getResultList());
    for (    UserArticleDto userArticleDto : paginatedList.getResultList()) {
      Article article=articleMap.get(userArticleDto.getArticleId());
      if (article.getTitle() != null) {
        userArticleDto.setArticleTitle(article.getTitle());
      }
      if (article.getDescription() != null) {
        userArticleDto.setArticleDescription(article.getDescription());
      }
      if (userArticleDto.getId() == null) {
        UserArticle userArticle=new UserArticle();
        userArticle.setArticleId(userArticleDto.getArticleId());
        userArticle.setUserId(userId);
        userArticle.setReadDate(new Date());
        String userArticleId=userArticleDao.create(userArticle);
        userArticleDto.setId(userArticleId);
        userArticleDto.setReadTimestamp(userArticle.getReadDate().getTime());
      }
    }
  }
 else {
    paginatedList.setResultList(new ArrayList<UserArticleDto>());
  }
  return paginatedList;
}