Program: 107050
Project: 107050
Buggy source:
public void upgradeLoadBalancingRules(Connection conn){
  try {
    PreparedStatement pstmt=conn.prepareStatement("String_Node_Str");
    ResultSet rs=pstmt.executeQuery();
    ArrayList<Object[]> lbs=new ArrayList<Object[]>();
    while (rs.next()) {
      Object[] lb=new Object[10];
      lb[0]=rs.getString(1);
      lb[1]=rs.getString(2);
      lb[2]=rs.getString(3);
      lb[3]=rs.getString(4);
      lb[4]=rs.getString(5);
      lb[5]=rs.getLong(6);
      lbs.add(lb);
    }
    rs.close();
    pstmt.close();
    if (!lbs.isEmpty()) {
      s_logger.debug("String_Node_Str" + lbs.size() + "String_Node_Str");
      pstmt=conn.prepareStatement("String_Node_Str");
      rs=pstmt.executeQuery();
      long newLbId=0;
      while (rs.next()) {
        newLbId=rs.getLong(1);
      }
      rs.close();
      pstmt.close();
      for (      Object[] lb : lbs) {
        String name=(String)lb[0];
        String publicIp=(String)lb[1];
        String sourcePort=(String)lb[2];
        String destPort=(String)lb[3];
        String algorithm=(String)lb[4];
        Long originalLbId=(Long)lb[5];
        newLbId=newLbId + 1;
        pstmt=conn.prepareStatement("String_Node_Str");
        pstmt.setString(1,publicIp);
        rs=pstmt.executeQuery();
        if (!rs.next()) {
          s_logger.warn("String_Node_Str" + publicIp + "String_Node_Str"+ originalLbId+ "String_Node_Str");
          continue;
        }
        int ipAddressId=rs.getInt(1);
        long accountId=rs.getLong(2);
        long domainId=rs.getLong(3);
        long networkId=rs.getLong(4);
        rs.close();
        pstmt.close();
        s_logger.trace("String_Node_Str");
        pstmt=conn.prepareStatement("String_Node_Str");
        pstmt.setLong(1,newLbId);
        pstmt.setInt(2,ipAddressId);
        pstmt.setInt(3,Integer.valueOf(sourcePort));
        pstmt.setInt(4,Integer.valueOf(sourcePort));
        pstmt.setString(5,"String_Node_Str");
        pstmt.setLong(6,accountId);
        pstmt.setLong(7,domainId);
        pstmt.setLong(8,networkId);
        pstmt.setString(9,UUID.randomUUID().toString());
        pstmt.executeUpdate();
        pstmt.close();
        s_logger.trace("String_Node_Str");
        s_logger.trace("String_Node_Str");
        pstmt=conn.prepareStatement("String_Node_Str");
        pstmt.setLong(1,newLbId);
        pstmt.setString(2,name);
        pstmt.setInt(3,Integer.valueOf(destPort));
        pstmt.setInt(4,Integer.valueOf(destPort));
        pstmt.setString(5,algorithm);
        pstmt.executeUpdate();
        pstmt.close();
        s_logger.trace("String_Node_Str");
        s_logger.trace("String_Node_Str");
        pstmt=conn.prepareStatement("String_Node_Str");
        pstmt.setLong(1,originalLbId);
        rs=pstmt.executeQuery();
        ArrayList<Object[]> lbMaps=new ArrayList<Object[]>();
        while (rs.next()) {
          Object[] lbMap=new Object[10];
          lbMap[0]=rs.getLong(1);
          lbMaps.add(lbMap);
        }
        rs.close();
        pstmt.close();
        pstmt=conn.prepareStatement("String_Node_Str");
        pstmt.setLong(1,newLbId);
        pstmt.setLong(2,originalLbId);
        pstmt.executeUpdate();
        pstmt.close();
        s_logger.trace("String_Node_Str");
      }
    }
    s_logger.debug("String_Node_Str");
  }
 catch (  SQLException e) {
    throw new CloudRuntimeException("String_Node_Str",e);
  }
}

Fixed version (ground truth):
public void upgradeLoadBalancingRules(Connection conn){
  try {
    PreparedStatement pstmt=conn.prepareStatement("String_Node_Str");
    ResultSet rs=pstmt.executeQuery();
    ArrayList<Object[]> lbs=new ArrayList<Object[]>();
    while (rs.next()) {
      Object[] lb=new Object[10];
      lb[0]=rs.getString(1);
      lb[1]=rs.getString(2);
      lb[2]=rs.getString(3);
      lb[3]=rs.getString(4);
      lb[4]=rs.getString(5);
      lb[5]=rs.getLong(6);
      lbs.add(lb);
    }
    rs.close();
    pstmt.close();
    if (!lbs.isEmpty()) {
      s_logger.debug("String_Node_Str" + lbs.size() + "String_Node_Str");
      pstmt=conn.prepareStatement("String_Node_Str");
      rs=pstmt.executeQuery();
      long newLbId=0;
      while (rs.next()) {
        newLbId=rs.getLong(1);
      }
      rs.close();
      pstmt.close();
      for (      Object[] lb : lbs) {
        String name=(String)lb[0];
        String publicIp=(String)lb[1];
        String sourcePort=(String)lb[2];
        String destPort=(String)lb[3];
        String algorithm=(String)lb[4];
        Long originalLbId=(Long)lb[5];
        newLbId=newLbId + 1;
        pstmt=conn.prepareStatement("String_Node_Str");
        pstmt.setString(1,publicIp);
        rs=pstmt.executeQuery();
        if (!rs.next()) {
          s_logger.warn("String_Node_Str" + publicIp + "String_Node_Str"+ originalLbId+ "String_Node_Str");
          pstmt=conn.prepareStatement("String_Node_Str");
          pstmt.setLong(1,originalLbId);
          pstmt.executeUpdate();
          pstmt=conn.prepareStatement("String_Node_Str");
          pstmt.setLong(1,originalLbId);
          pstmt.executeUpdate();
          continue;
        }
        int ipAddressId=rs.getInt(1);
        long accountId=rs.getLong(2);
        long domainId=rs.getLong(3);
        long networkId=rs.getLong(4);
        rs.close();
        pstmt.close();
        s_logger.trace("String_Node_Str");
        pstmt=conn.prepareStatement("String_Node_Str");
        pstmt.setLong(1,newLbId);
        pstmt.setInt(2,ipAddressId);
        pstmt.setInt(3,Integer.valueOf(sourcePort));
        pstmt.setInt(4,Integer.valueOf(sourcePort));
        pstmt.setString(5,"String_Node_Str");
        pstmt.setLong(6,accountId);
        pstmt.setLong(7,domainId);
        pstmt.setLong(8,networkId);
        pstmt.setString(9,UUID.randomUUID().toString());
        pstmt.executeUpdate();
        pstmt.close();
        s_logger.trace("String_Node_Str");
        s_logger.trace("String_Node_Str");
        pstmt=conn.prepareStatement("String_Node_Str");
        pstmt.setLong(1,newLbId);
        pstmt.setString(2,name);
        pstmt.setInt(3,Integer.valueOf(destPort));
        pstmt.setInt(4,Integer.valueOf(destPort));
        pstmt.setString(5,algorithm);
        pstmt.executeUpdate();
        pstmt.close();
        s_logger.trace("String_Node_Str");
        s_logger.trace("String_Node_Str");
        pstmt=conn.prepareStatement("String_Node_Str");
        pstmt.setLong(1,originalLbId);
        rs=pstmt.executeQuery();
        ArrayList<Object[]> lbMaps=new ArrayList<Object[]>();
        while (rs.next()) {
          Object[] lbMap=new Object[10];
          lbMap[0]=rs.getLong(1);
          lbMaps.add(lbMap);
        }
        rs.close();
        pstmt.close();
        pstmt=conn.prepareStatement("String_Node_Str");
        pstmt.setLong(1,newLbId);
        pstmt.setLong(2,originalLbId);
        pstmt.executeUpdate();
        pstmt.close();
        s_logger.trace("String_Node_Str");
      }
    }
    s_logger.debug("String_Node_Str");
  }
 catch (  SQLException e) {
    throw new CloudRuntimeException("String_Node_Str",e);
  }
}