Program: 105890
Project: 105890
Buggy source:
private void secondaryIpsAccountAndDomainIdsUpdate(Connection conn){
  PreparedStatement pstmt=null;
  PreparedStatement pstmtVm=null;
  PreparedStatement pstmtNw=null;
  PreparedStatement pstmtUpdate=null;
  ResultSet rs1=null;
  ResultSet vmRs=null;
  ResultSet networkRs=null;
  String secondIpsSql="String_Node_Str";
  try {
    pstmt=conn.prepareStatement(secondIpsSql);
    rs1=pstmt.executeQuery();
    while (rs1.next()) {
      long ipId=rs1.getLong(1);
      long vmId=rs1.getLong(2);
      long networkId=rs1.getLong(3);
      long accountId=rs1.getLong(4);
      long domainId=rs1.getLong(5);
      String ipAddr=rs1.getString(6);
      pstmtVm=conn.prepareStatement("String_Node_Str");
      pstmtVm.setLong(1,vmId);
      vmRs=pstmtVm.executeQuery();
      if (vmRs.next()) {
        long vmAccountId=vmRs.getLong(1);
        long vmDomainId=vmRs.getLong(2);
        if (vmAccountId != accountId && vmAccountId != domainId) {
          pstmtUpdate=conn.prepareStatement("String_Node_Str");
          pstmtUpdate.setLong(1,vmAccountId);
          pstmtUpdate.setLong(2,vmDomainId);
          pstmtUpdate.setLong(3,ipId);
          pstmtUpdate.executeUpdate();
          pstmtUpdate.close();
          pstmtNw=conn.prepareStatement("String_Node_Str");
          pstmtNw.setLong(1,networkId);
          networkRs=pstmtNw.executeQuery();
          if (networkRs.next()) {
            String guesttype=networkRs.getString(1);
            if (guesttype == Network.GuestType.Shared.toString()) {
              pstmtUpdate=conn.prepareStatement("String_Node_Str");
              pstmtUpdate.setLong(1,vmAccountId);
              pstmtUpdate.setLong(2,vmDomainId);
              pstmtUpdate.setString(3,ipAddr);
              pstmtUpdate.executeUpdate();
              pstmtUpdate.close();
            }
          }
          networkRs.close();
          networkRs=null;
          pstmtNw.close();
          pstmtNw=null;
        }
      }
      pstmtVm.close();
      pstmtVm=null;
      vmRs.close();
      vmRs=null;
    }
  }
 catch (  SQLException e) {
    throw new CloudRuntimeException("String_Node_Str",e);
  }
 finally {
    if (pstmt != null) {
      try {
        pstmt.close();
      }
 catch (      SQLException e) {
      }
    }
    if (rs1 != null) {
      try {
        rs1.close();
      }
 catch (      SQLException e) {
      }
    }
    if (pstmtVm != null) {
      try {
        pstmtVm.close();
      }
 catch (      SQLException e) {
      }
    }
    if (vmRs != null) {
      try {
        vmRs.close();
      }
 catch (      SQLException e) {
      }
    }
    if (pstmtNw != null) {
      try {
        pstmtNw.close();
      }
 catch (      SQLException e) {
      }
    }
    if (networkRs != null) {
      try {
        networkRs.close();
      }
 catch (      SQLException e) {
      }
    }
  }
  s_logger.debug("String_Node_Str");
}

Fixed version (ground truth):
private void secondaryIpsAccountAndDomainIdsUpdate(Connection conn){
  PreparedStatement pstmt=null;
  PreparedStatement pstmtVm=null;
  PreparedStatement pstmtNw=null;
  PreparedStatement pstmtUpdate=null;
  ResultSet rs1=null;
  ResultSet vmRs=null;
  ResultSet networkRs=null;
  String secondIpsSql="String_Node_Str";
  try {
    pstmt=conn.prepareStatement(secondIpsSql);
    rs1=pstmt.executeQuery();
    while (rs1.next()) {
      long ipId=rs1.getLong(1);
      long vmId=rs1.getLong(2);
      long networkId=rs1.getLong(3);
      long accountId=rs1.getLong(4);
      long domainId=rs1.getLong(5);
      String ipAddr=rs1.getString(6);
      pstmtVm=conn.prepareStatement("String_Node_Str");
      pstmtVm.setLong(1,vmId);
      vmRs=pstmtVm.executeQuery();
      if (vmRs.next()) {
        long vmAccountId=vmRs.getLong(1);
        long vmDomainId=vmRs.getLong(2);
        if (vmAccountId != accountId && vmAccountId != domainId) {
          pstmtUpdate=conn.prepareStatement("String_Node_Str");
          pstmtUpdate.setLong(1,vmAccountId);
          pstmtUpdate.setLong(2,vmDomainId);
          pstmtUpdate.setLong(3,ipId);
          pstmtUpdate.executeUpdate();
          pstmtUpdate.close();
          pstmtNw=conn.prepareStatement("String_Node_Str");
          pstmtNw.setLong(1,networkId);
          networkRs=pstmtNw.executeQuery();
          if (networkRs.next()) {
            String guesttype=networkRs.getString(1);
            if (guesttype.equals(Network.GuestType.Shared.toString())) {
              pstmtUpdate=conn.prepareStatement("String_Node_Str");
              pstmtUpdate.setLong(1,vmAccountId);
              pstmtUpdate.setLong(2,vmDomainId);
              pstmtUpdate.setString(3,ipAddr);
              pstmtUpdate.executeUpdate();
              pstmtUpdate.close();
            }
          }
          networkRs.close();
          networkRs=null;
          pstmtNw.close();
          pstmtNw=null;
        }
      }
      pstmtVm.close();
      pstmtVm=null;
      vmRs.close();
      vmRs=null;
    }
  }
 catch (  SQLException e) {
    throw new CloudRuntimeException("String_Node_Str",e);
  }
 finally {
    if (pstmt != null) {
      try {
        pstmt.close();
      }
 catch (      SQLException e) {
      }
    }
    if (rs1 != null) {
      try {
        rs1.close();
      }
 catch (      SQLException e) {
      }
    }
    if (pstmtVm != null) {
      try {
        pstmtVm.close();
      }
 catch (      SQLException e) {
      }
    }
    if (vmRs != null) {
      try {
        vmRs.close();
      }
 catch (      SQLException e) {
      }
    }
    if (pstmtNw != null) {
      try {
        pstmtNw.close();
      }
 catch (      SQLException e) {
      }
    }
    if (networkRs != null) {
      try {
        networkRs.close();
      }
 catch (      SQLException e) {
      }
    }
  }
  s_logger.debug("String_Node_Str");
}