Program: 105225
Project: 105225
Buggy source:
public void upgradePortForwardingRules(Connection conn){
  try {
    PreparedStatement pstmt=conn.prepareStatement("String_Node_Str");
    ResultSet rs=pstmt.executeQuery();
    ArrayList<Object[]> rules=new ArrayList<Object[]>();
    while (rs.next()) {
      Object[] rule=new Object[10];
      rule[0]=rs.getLong(1);
      rule[1]=rs.getString(2);
      rule[2]=rs.getString(3);
      rule[3]=rs.getString(4);
      rule[4]=rs.getString(5);
      rule[5]=rs.getString(6);
      rules.add(rule);
    }
    rs.close();
    pstmt.close();
    if (!rules.isEmpty()) {
      s_logger.debug("String_Node_Str" + rules.size() + "String_Node_Str");
      for (      Object[] rule : rules) {
        long id=(Long)rule[0];
        String sourcePort=(String)rule[2];
        String protocol=(String)rule[5];
        String publicIp=(String)rule[1];
        pstmt=conn.prepareStatement("String_Node_Str");
        pstmt.setString(1,publicIp);
        rs=pstmt.executeQuery();
        if (!rs.next()) {
          s_logger.error("String_Node_Str" + publicIp);
          throw new CloudRuntimeException("String_Node_Str" + publicIp);
        }
        int ipAddressId=rs.getInt(1);
        long accountId=rs.getLong(2);
        long domainId=rs.getLong(3);
        long networkId=rs.getLong(4);
        String privateIp=(String)rule[3];
        rs.close();
        pstmt.close();
        s_logger.trace("String_Node_Str");
        pstmt=conn.prepareStatement("String_Node_Str");
        pstmt.setLong(1,networkId);
        pstmt.setString(2,privateIp);
        rs=pstmt.executeQuery();
        if (!rs.next()) {
          s_logger.warn("String_Node_Str" + privateIp + "String_Node_Str"+ accountId+ "String_Node_Str");
        }
 else {
          long instanceId=rs.getLong(1);
          s_logger.debug("String_Node_Str" + instanceId);
          s_logger.trace("String_Node_Str");
          pstmt=conn.prepareStatement("String_Node_Str");
          pstmt.setLong(1,id);
          pstmt.setInt(2,ipAddressId);
          pstmt.setInt(3,Integer.parseInt(sourcePort.trim()));
          pstmt.setInt(4,Integer.parseInt(sourcePort.trim()));
          pstmt.setString(5,protocol);
          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");
          rs.close();
          pstmt.close();
          String privatePort=(String)rule[4];
          pstmt=conn.prepareStatement("String_Node_Str");
          pstmt.setLong(1,id);
          pstmt.setLong(2,instanceId);
          pstmt.setString(3,privateIp);
          pstmt.setInt(4,Integer.valueOf(privatePort.trim()));
          pstmt.setInt(5,Integer.valueOf(privatePort.trim()));
          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 upgradePortForwardingRules(Connection conn){
  try {
    PreparedStatement pstmt=conn.prepareStatement("String_Node_Str");
    ResultSet rs=pstmt.executeQuery();
    ArrayList<Object[]> rules=new ArrayList<Object[]>();
    while (rs.next()) {
      Object[] rule=new Object[10];
      rule[0]=rs.getLong(1);
      rule[1]=rs.getString(2);
      rule[2]=rs.getString(3);
      rule[3]=rs.getString(4);
      rule[4]=rs.getString(5);
      rule[5]=rs.getString(6);
      rules.add(rule);
    }
    rs.close();
    pstmt.close();
    if (!rules.isEmpty()) {
      s_logger.debug("String_Node_Str" + rules.size() + "String_Node_Str");
      for (      Object[] rule : rules) {
        long id=(Long)rule[0];
        String sourcePort=(String)rule[2];
        String protocol=(String)rule[5];
        String publicIp=(String)rule[1];
        pstmt=conn.prepareStatement("String_Node_Str");
        pstmt.setString(1,publicIp);
        rs=pstmt.executeQuery();
        if (!rs.next()) {
          s_logger.error("String_Node_Str" + publicIp);
          throw new CloudRuntimeException("String_Node_Str" + publicIp);
        }
        int ipAddressId=rs.getInt(1);
        long accountId=rs.getLong(2);
        long domainId=rs.getLong(3);
        long networkId=rs.getLong(4);
        String privateIp=(String)rule[3];
        rs.close();
        pstmt.close();
        s_logger.trace("String_Node_Str");
        pstmt=conn.prepareStatement("String_Node_Str");
        pstmt.setLong(1,networkId);
        pstmt.setString(2,privateIp);
        rs=pstmt.executeQuery();
        if (!rs.next()) {
          s_logger.warn("String_Node_Str" + privateIp + "String_Node_Str"+ accountId+ "String_Node_Str");
        }
 else {
          long instanceId=rs.getLong(1);
          s_logger.debug("String_Node_Str" + instanceId);
          s_logger.trace("String_Node_Str");
          pstmt=conn.prepareStatement("String_Node_Str");
          pstmt.setLong(1,id);
          pstmt.setInt(2,ipAddressId);
          pstmt.setInt(3,Integer.parseInt(sourcePort.trim()));
          pstmt.setInt(4,Integer.parseInt(sourcePort.trim()));
          pstmt.setString(5,protocol);
          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");
          rs.close();
          pstmt.close();
          String privatePort=(String)rule[4];
          pstmt=conn.prepareStatement("String_Node_Str");
          pstmt.setLong(1,id);
          pstmt.setLong(2,instanceId);
          pstmt.setString(3,privateIp);
          pstmt.setInt(4,Integer.parseInt(privatePort.trim()));
          pstmt.setInt(5,Integer.parseInt(privatePort.trim()));
          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);
  }
}