Program: 107359
Project: 107359
Buggy source:
@Override public List<VMTemplateVO> searchTemplates(String name,String keyword,TemplateFilter templateFilter,boolean isIso,Boolean bootable,Account account,DomainVO domain,Long pageSize,Long startIndex,Long zoneId,HypervisorType hyperType){
  Transaction txn=Transaction.currentTxn();
  txn.start();
  List<VMTemplateVO> templates=new ArrayList<VMTemplateVO>();
  PreparedStatement pstmt=null;
  ResultSet rs=null;
  try {
    short accountType;
    String accountId=null;
    if (account != null) {
      accountType=account.getType();
      accountId=Long.toString(account.getId());
    }
 else {
      accountType=Account.ACCOUNT_TYPE_ADMIN;
    }
    String guestOSJoin="String_Node_Str";
    if (isIso && !hyperType.equals(HypervisorType.None)) {
      guestOSJoin="String_Node_Str";
    }
    String sql=SELECT_ALL + guestOSJoin;
    String whereClause="String_Node_Str";
    if (templateFilter == TemplateFilter.featured) {
      whereClause+="String_Node_Str";
    }
 else     if ((templateFilter == TemplateFilter.self || templateFilter == TemplateFilter.selfexecutable) && accountType != Account.ACCOUNT_TYPE_ADMIN) {
      if (accountType == Account.ACCOUNT_TYPE_DOMAIN_ADMIN) {
        whereClause+="String_Node_Str" + domain.getPath() + "String_Node_Str";
      }
 else {
        whereClause+="String_Node_Str" + accountId;
      }
    }
 else     if (templateFilter == TemplateFilter.sharedexecutable && accountType != Account.ACCOUNT_TYPE_ADMIN) {
      if (accountType == Account.ACCOUNT_TYPE_NORMAL) {
        whereClause+="String_Node_Str" + "String_Node_Str" + accountId + "String_Node_Str"+ "String_Node_Str"+ accountId+ "String_Node_Str";
      }
 else {
        whereClause+="String_Node_Str" + domain.getPath() + "String_Node_Str";
      }
    }
 else     if (templateFilter == TemplateFilter.executable && accountId != null) {
      whereClause+="String_Node_Str" + accountId + "String_Node_Str";
    }
 else     if (templateFilter == TemplateFilter.community) {
      whereClause+="String_Node_Str";
    }
 else     if (templateFilter == TemplateFilter.all && accountType == Account.ACCOUNT_TYPE_ADMIN) {
      whereClause+="String_Node_Str";
    }
 else     if (accountType != Account.ACCOUNT_TYPE_ADMIN) {
      return templates;
    }
    if (whereClause.equals("String_Node_Str")) {
      whereClause+="String_Node_Str";
    }
 else     if (!whereClause.equals("String_Node_Str")) {
      whereClause+="String_Node_Str";
    }
    sql+=whereClause + getExtrasWhere(templateFilter,name,keyword,isIso,bootable,hyperType) + getOrderByLimit(pageSize,startIndex);
    pstmt=txn.prepareStatement(sql);
    rs=pstmt.executeQuery();
    while (rs.next()) {
      VMTemplateVO tmplt=toEntityBean(rs,false);
      if (zoneId != null) {
        VMTemplateZoneVO vtzvo=_templateZoneDao.findByZoneTemplate(zoneId,tmplt.getId());
        if (vtzvo != null) {
          templates.add(tmplt);
        }
      }
 else {
        templates.add(tmplt);
      }
    }
    if (isIso && (account.getType() == Account.ACCOUNT_TYPE_NORMAL)) {
      List<VMTemplateVO> xenToolsIso=xenToolsIsoSearch();
      templates.addAll(xenToolsIso);
    }
  }
 catch (  Exception e) {
    s_logger.warn("String_Node_Str",e);
  }
 finally {
    try {
      if (rs != null) {
        rs.close();
      }
      if (pstmt != null) {
        pstmt.close();
      }
      txn.commit();
    }
 catch (    SQLException sqle) {
      s_logger.warn("String_Node_Str",sqle);
    }
  }
  return templates;
}

Fixed version (ground truth):
@Override public List<VMTemplateVO> searchTemplates(String name,String keyword,TemplateFilter templateFilter,boolean isIso,Boolean bootable,Account account,DomainVO domain,Long pageSize,Long startIndex,Long zoneId,HypervisorType hyperType){
  Transaction txn=Transaction.currentTxn();
  txn.start();
  List<VMTemplateVO> templates=new ArrayList<VMTemplateVO>();
  PreparedStatement pstmt=null;
  ResultSet rs=null;
  try {
    short accountType;
    String accountId=null;
    if (account != null) {
      accountType=account.getType();
      accountId=Long.toString(account.getId());
    }
 else {
      accountType=Account.ACCOUNT_TYPE_ADMIN;
    }
    String guestOSJoin="String_Node_Str";
    if (isIso && !hyperType.equals(HypervisorType.None)) {
      guestOSJoin="String_Node_Str";
    }
    String sql=SELECT_ALL + guestOSJoin;
    String whereClause="String_Node_Str";
    if (templateFilter == TemplateFilter.featured) {
      whereClause+="String_Node_Str";
    }
 else     if ((templateFilter == TemplateFilter.self || templateFilter == TemplateFilter.selfexecutable) && accountType != Account.ACCOUNT_TYPE_ADMIN) {
      if (accountType == Account.ACCOUNT_TYPE_DOMAIN_ADMIN) {
        whereClause+="String_Node_Str" + domain.getPath() + "String_Node_Str";
      }
 else {
        whereClause+="String_Node_Str" + accountId;
      }
    }
 else     if (templateFilter == TemplateFilter.sharedexecutable && accountType != Account.ACCOUNT_TYPE_ADMIN) {
      if (accountType == Account.ACCOUNT_TYPE_NORMAL) {
        whereClause+="String_Node_Str" + "String_Node_Str" + accountId + "String_Node_Str"+ "String_Node_Str"+ accountId+ "String_Node_Str";
      }
 else {
        whereClause+="String_Node_Str" + domain.getPath() + "String_Node_Str";
      }
    }
 else     if (templateFilter == TemplateFilter.executable && accountId != null) {
      whereClause+="String_Node_Str" + accountId + "String_Node_Str";
    }
 else     if (templateFilter == TemplateFilter.community) {
      whereClause+="String_Node_Str";
    }
 else     if (templateFilter == TemplateFilter.all && accountType == Account.ACCOUNT_TYPE_ADMIN) {
      whereClause+="String_Node_Str";
    }
 else     if (accountType != Account.ACCOUNT_TYPE_ADMIN) {
      return templates;
    }
    if (whereClause.equals("String_Node_Str")) {
      whereClause+="String_Node_Str";
    }
 else     if (!whereClause.equals("String_Node_Str")) {
      whereClause+="String_Node_Str";
    }
    sql+=whereClause + getExtrasWhere(templateFilter,name,keyword,isIso,bootable,hyperType) + getOrderByLimit(pageSize,startIndex);
    pstmt=txn.prepareStatement(sql);
    rs=pstmt.executeQuery();
    while (rs.next()) {
      VMTemplateVO tmplt=toEntityBean(rs,false);
      if (zoneId != null) {
        VMTemplateZoneVO vtzvo=_templateZoneDao.findByZoneTemplate(zoneId,tmplt.getId());
        if (vtzvo != null) {
          templates.add(tmplt);
        }
      }
 else {
        templates.add(tmplt);
      }
    }
    if (isIso && (account.getType() == Account.ACCOUNT_TYPE_NORMAL)) {
      List<VMTemplateVO> publicIsos=publicIsoSearch();
      templates.addAll(publicIsos);
    }
  }
 catch (  Exception e) {
    s_logger.warn("String_Node_Str",e);
  }
 finally {
    try {
      if (rs != null) {
        rs.close();
      }
      if (pstmt != null) {
        pstmt.close();
      }
      txn.commit();
    }
 catch (    SQLException sqle) {
      s_logger.warn("String_Node_Str",sqle);
    }
  }
  return templates;
}