Program: 106731
Project: 106731
Buggy source:
private void updateFirewallRules(Connection conn){
  PreparedStatement pstmt=null;
  ResultSet rs=null;
  long currentRuleId=0;
  try {
    pstmt=conn.prepareStatement("String_Node_Str");
    rs=pstmt.executeQuery();
    while (rs.next()) {
      long id=rs.getLong(1);
      long ipId=rs.getLong(2);
      int startPort=rs.getInt(3);
      int endPort=rs.getInt(4);
      String protocol=rs.getString(5);
      long accountId=rs.getLong(6);
      long domainId=rs.getLong(7);
      long networkId=rs.getLong(8);
      currentRuleId=id;
      Long firewallRuleId=null;
      pstmt=conn.prepareStatement("String_Node_Str");
      pstmt.setLong(1,ipId);
      pstmt.setInt(2,startPort);
      pstmt.setInt(3,endPort);
      pstmt.setString(4,protocol);
      pstmt.setLong(5,accountId);
      pstmt.setLong(6,domainId);
      pstmt.setLong(7,networkId);
      pstmt.setString(8,UUID.randomUUID().toString());
      pstmt.setLong(9,id);
      s_logger.debug("String_Node_Str" + pstmt);
      pstmt.executeUpdate();
      pstmt=conn.prepareStatement("String_Node_Str");
      pstmt.setInt(1,startPort);
      pstmt.setInt(2,endPort);
      pstmt.setString(3,protocol);
      ResultSet rs1=pstmt.executeQuery();
      if (rs1.next()) {
        firewallRuleId=rs1.getLong(1);
      }
 else {
        throw new CloudRuntimeException("String_Node_Str" + protocol + "String_Node_Str"+ startPort+ "String_Node_Str"+ endPort);
      }
      pstmt=conn.prepareStatement("String_Node_Str");
      pstmt.setLong(1,id);
      ResultSet rs2=pstmt.executeQuery();
      if (rs2.next()) {
        pstmt=conn.prepareStatement("String_Node_Str");
        pstmt.setLong(1,firewallRuleId);
        pstmt.setLong(2,id);
        s_logger.debug("String_Node_Str" + id + "String_Node_Str"+ firewallRuleId+ "String_Node_Str"+ pstmt);
        pstmt.executeUpdate();
      }
 else {
        pstmt=conn.prepareStatement("String_Node_Str");
        pstmt.setLong(1,firewallRuleId);
        s_logger.debug("String_Node_Str" + firewallRuleId + "String_Node_Str"+ pstmt);
        pstmt.executeUpdate();
      }
    }
  }
 catch (  SQLException e) {
    throw new CloudRuntimeException("String_Node_Str" + currentRuleId,e);
  }
 finally {
    try {
      if (rs != null) {
        rs.close();
      }
      if (pstmt != null) {
        pstmt.close();
      }
    }
 catch (    SQLException e) {
    }
  }
}

Fixed version (ground truth):
private void updateFirewallRules(Connection conn){
  PreparedStatement pstmt=null;
  ResultSet rs=null;
  long currentRuleId=0;
  try {
    pstmt=conn.prepareStatement("String_Node_Str");
    rs=pstmt.executeQuery();
    while (rs.next()) {
      long id=rs.getLong(1);
      long ipId=rs.getLong(2);
      int startPort=rs.getInt(3);
      int endPort=rs.getInt(4);
      String protocol=rs.getString(5);
      long accountId=rs.getLong(6);
      long domainId=rs.getLong(7);
      long networkId=rs.getLong(8);
      currentRuleId=id;
      Long firewallRuleId=null;
      pstmt=conn.prepareStatement("String_Node_Str");
      pstmt.setLong(1,ipId);
      pstmt.setInt(2,startPort);
      pstmt.setInt(3,endPort);
      pstmt.setString(4,protocol);
      pstmt.setLong(5,accountId);
      pstmt.setLong(6,domainId);
      pstmt.setLong(7,networkId);
      pstmt.setString(8,UUID.randomUUID().toString());
      pstmt.setLong(9,id);
      s_logger.debug("String_Node_Str" + pstmt);
      pstmt.executeUpdate();
      pstmt=conn.prepareStatement("String_Node_Str");
      pstmt.setInt(1,startPort);
      pstmt.setInt(2,endPort);
      pstmt.setString(3,protocol);
      pstmt.setLong(4,ipId);
      pstmt.setLong(5,networkId);
      ResultSet rs1=pstmt.executeQuery();
      if (rs1.next()) {
        firewallRuleId=rs1.getLong(1);
      }
 else {
        throw new CloudRuntimeException("String_Node_Str" + protocol + "String_Node_Str"+ startPort+ "String_Node_Str"+ endPort);
      }
      pstmt=conn.prepareStatement("String_Node_Str");
      pstmt.setLong(1,id);
      ResultSet rs2=pstmt.executeQuery();
      if (rs2.next()) {
        pstmt=conn.prepareStatement("String_Node_Str");
        pstmt.setLong(1,firewallRuleId);
        pstmt.setLong(2,id);
        s_logger.debug("String_Node_Str" + id + "String_Node_Str"+ firewallRuleId+ "String_Node_Str"+ pstmt);
        pstmt.executeUpdate();
      }
 else {
        pstmt=conn.prepareStatement("String_Node_Str");
        pstmt.setLong(1,firewallRuleId);
        s_logger.debug("String_Node_Str" + firewallRuleId + "String_Node_Str"+ pstmt);
        pstmt.executeUpdate();
      }
    }
  }
 catch (  SQLException e) {
    throw new CloudRuntimeException("String_Node_Str" + currentRuleId,e);
  }
 finally {
    try {
      if (rs != null) {
        rs.close();
      }
      if (pstmt != null) {
        pstmt.close();
      }
    }
 catch (    SQLException e) {
    }
  }
}