Program: 89104
Project: 89104
Buggy source:
private void setupPhysicalNetworks(Connection conn){
  PreparedStatement pstmt=null;
  ResultSet rs=null;
  PreparedStatement pstmtUpdate=null;
  try {
    String xenPublicLabel=getNetworkLabelFromConfig(conn,"String_Node_Str");
    String xenPrivateLabel=getNetworkLabelFromConfig(conn,"String_Node_Str");
    String xenStorageLabel=getNetworkLabelFromConfig(conn,"String_Node_Str");
    String xenGuestLabel=getNetworkLabelFromConfig(conn,"String_Node_Str");
    String kvmPublicLabel=getNetworkLabelFromConfig(conn,"String_Node_Str");
    String kvmPrivateLabel=getNetworkLabelFromConfig(conn,"String_Node_Str");
    String kvmGuestLabel=getNetworkLabelFromConfig(conn,"String_Node_Str");
    String vmwarePublicLabel=getNetworkLabelFromConfig(conn,"String_Node_Str");
    String vmwarePrivateLabel=getNetworkLabelFromConfig(conn,"String_Node_Str");
    String vmwareGuestLabel=getNetworkLabelFromConfig(conn,"String_Node_Str");
    pstmt=conn.prepareStatement("String_Node_Str");
    rs=pstmt.executeQuery();
    while (rs.next()) {
      long zoneId=rs.getLong(1);
      Long domainId=rs.getLong(2);
      String networkType=rs.getString(3);
      String vnet=rs.getString(4);
      String zoneName=rs.getString(5);
      PreparedStatement pstmt2=conn.prepareStatement("String_Node_Str" + zoneId);
      ResultSet rsTags=pstmt2.executeQuery();
      if (rsTags.next()) {
        boolean isFirstPhysicalNtwk=true;
        do {
          s_logger.debug("String_Node_Str");
          String guestNetworkTag=rsTags.getString(1);
          long physicalNetworkId=addPhysicalNetworkToZone(conn,zoneId,zoneName,networkType,(isFirstPhysicalNtwk) ? vnet : null,domainId);
          if (isFirstPhysicalNtwk) {
            addTrafficType(conn,physicalNetworkId,"String_Node_Str",xenPublicLabel,kvmPublicLabel,vmwarePublicLabel);
            addTrafficType(conn,physicalNetworkId,"String_Node_Str",xenPrivateLabel,kvmPrivateLabel,vmwarePrivateLabel);
            addTrafficType(conn,physicalNetworkId,"String_Node_Str",xenStorageLabel,null,null);
          }
          addTrafficType(conn,physicalNetworkId,"String_Node_Str",guestNetworkTag,kvmGuestLabel,vmwareGuestLabel);
          addDefaultServiceProviders(conn,physicalNetworkId,zoneId);
          PreparedStatement pstmt3=conn.prepareStatement("String_Node_Str" + guestNetworkTag + "String_Node_Str");
          ResultSet rsNet=pstmt3.executeQuery();
          s_logger.debug("String_Node_Str");
          s_logger.debug("String_Node_Str");
          s_logger.debug("String_Node_Str");
          while (rsNet.next()) {
            Long networkId=rsNet.getLong(1);
            addPhysicalNtwk_To_Ntwk_IP_Vlan(conn,physicalNetworkId,networkId);
          }
          pstmt3.close();
          if (isFirstPhysicalNtwk) {
            s_logger.debug("String_Node_Str");
            String updateVnet="String_Node_Str" + physicalNetworkId + "String_Node_Str"+ zoneId;
            pstmtUpdate=conn.prepareStatement(updateVnet);
            pstmtUpdate.executeUpdate();
            pstmtUpdate.close();
          }
          isFirstPhysicalNtwk=false;
        }
 while (rsTags.next());
        pstmt2.close();
      }
 else {
        long physicalNetworkId=addPhysicalNetworkToZone(conn,zoneId,zoneName,networkType,vnet,domainId);
        addTrafficType(conn,physicalNetworkId,"String_Node_Str",xenPublicLabel,kvmPublicLabel,vmwarePublicLabel);
        addTrafficType(conn,physicalNetworkId,"String_Node_Str",xenPrivateLabel,kvmPrivateLabel,vmwarePrivateLabel);
        addTrafficType(conn,physicalNetworkId,"String_Node_Str",xenStorageLabel,null,null);
        addTrafficType(conn,physicalNetworkId,"String_Node_Str",xenGuestLabel,kvmGuestLabel,vmwareGuestLabel);
        addDefaultServiceProviders(conn,physicalNetworkId,zoneId);
        s_logger.debug("String_Node_Str");
        String updateVnet="String_Node_Str" + physicalNetworkId + "String_Node_Str"+ zoneId;
        pstmtUpdate=conn.prepareStatement(updateVnet);
        pstmtUpdate.executeUpdate();
        pstmtUpdate.close();
        s_logger.debug("String_Node_Str");
        String updateVLAN="String_Node_Str" + physicalNetworkId + "String_Node_Str"+ zoneId;
        pstmtUpdate=conn.prepareStatement(updateVLAN);
        pstmtUpdate.executeUpdate();
        pstmtUpdate.close();
        s_logger.debug("String_Node_Str");
        String updateUsrIp="String_Node_Str" + physicalNetworkId + "String_Node_Str"+ zoneId;
        pstmtUpdate=conn.prepareStatement(updateUsrIp);
        pstmtUpdate.executeUpdate();
        pstmtUpdate.close();
        s_logger.debug("String_Node_Str");
        String updateNet="String_Node_Str" + physicalNetworkId + "String_Node_Str"+ zoneId+ "String_Node_Str";
        pstmtUpdate=conn.prepareStatement(updateNet);
        pstmtUpdate.executeUpdate();
        pstmtUpdate.close();
      }
    }
  }
 catch (  SQLException e) {
    throw new CloudRuntimeException("String_Node_Str",e);
  }
 finally {
    if (pstmtUpdate != null) {
      try {
        pstmtUpdate.close();
      }
 catch (      SQLException e) {
      }
    }
    if (rs != null) {
      try {
        rs.close();
      }
 catch (      SQLException e) {
      }
    }
    if (pstmt != null) {
      try {
        pstmt.close();
      }
 catch (      SQLException e) {
      }
    }
  }
}

Fixed version (ground truth):
private void setupPhysicalNetworks(Connection conn){
  PreparedStatement pstmt=null;
  ResultSet rs=null;
  PreparedStatement pstmtUpdate=null;
  try {
    String getNextNetworkSequenceSql="String_Node_Str";
    String advanceNetworkSequenceSql="String_Node_Str";
    String xenPublicLabel=getNetworkLabelFromConfig(conn,"String_Node_Str");
    String xenPrivateLabel=getNetworkLabelFromConfig(conn,"String_Node_Str");
    String xenStorageLabel=getNetworkLabelFromConfig(conn,"String_Node_Str");
    String xenGuestLabel=getNetworkLabelFromConfig(conn,"String_Node_Str");
    String kvmPublicLabel=getNetworkLabelFromConfig(conn,"String_Node_Str");
    String kvmPrivateLabel=getNetworkLabelFromConfig(conn,"String_Node_Str");
    String kvmGuestLabel=getNetworkLabelFromConfig(conn,"String_Node_Str");
    String vmwarePublicLabel=getNetworkLabelFromConfig(conn,"String_Node_Str");
    String vmwarePrivateLabel=getNetworkLabelFromConfig(conn,"String_Node_Str");
    String vmwareGuestLabel=getNetworkLabelFromConfig(conn,"String_Node_Str");
    pstmt=conn.prepareStatement("String_Node_Str");
    rs=pstmt.executeQuery();
    while (rs.next()) {
      long zoneId=rs.getLong(1);
      Long domainId=rs.getLong(2);
      String networkType=rs.getString(3);
      String vnet=rs.getString(4);
      String zoneName=rs.getString(5);
      PreparedStatement pstmt2=conn.prepareStatement(getNextNetworkSequenceSql);
      ResultSet rsSeq=pstmt2.executeQuery();
      rsSeq.next();
      long physicalNetworkId=rsSeq.getLong(1);
      rsSeq.close();
      pstmt2.close();
      pstmt2=conn.prepareStatement(advanceNetworkSequenceSql);
      pstmt2.executeUpdate();
      pstmt2.close();
      String uuid=UUID.randomUUID().toString();
      String broadcastDomainRange="String_Node_Str";
      if ("String_Node_Str".equals(networkType)) {
        broadcastDomainRange="String_Node_Str";
      }
      String values=null;
      values="String_Node_Str" + physicalNetworkId + "String_Node_Str";
      values+="String_Node_Str" + uuid + "String_Node_Str";
      values+="String_Node_Str" + zoneId + "String_Node_Str";
      values+="String_Node_Str" + vnet + "String_Node_Str";
      values+="String_Node_Str" + domainId + "String_Node_Str";
      values+="String_Node_Str" + broadcastDomainRange + "String_Node_Str";
      values+="String_Node_Str";
      values+="String_Node_Str" + zoneName + "String_Node_Str";
      values+="String_Node_Str";
      s_logger.debug("String_Node_Str" + physicalNetworkId + "String_Node_Str"+ zoneId);
      String sql="String_Node_Str" + values;
      pstmtUpdate=conn.prepareStatement(sql);
      pstmtUpdate.executeUpdate();
      pstmtUpdate.close();
      s_logger.debug("String_Node_Str");
      String insertTraficType="String_Node_Str";
      pstmtUpdate=conn.prepareStatement(insertTraficType);
      pstmtUpdate.setLong(1,physicalNetworkId);
      pstmtUpdate.setString(2,"String_Node_Str");
      pstmtUpdate.setString(3,xenPublicLabel);
      pstmtUpdate.setString(4,kvmPublicLabel);
      pstmtUpdate.setString(5,vmwarePublicLabel);
      pstmtUpdate.setString(6,UUID.randomUUID().toString());
      pstmtUpdate.executeUpdate();
      pstmtUpdate.close();
      pstmtUpdate=conn.prepareStatement(insertTraficType);
      pstmtUpdate.setLong(1,physicalNetworkId);
      pstmtUpdate.setString(2,"String_Node_Str");
      pstmtUpdate.setString(3,xenPrivateLabel);
      pstmtUpdate.setString(4,kvmPrivateLabel);
      pstmtUpdate.setString(5,vmwarePrivateLabel);
      pstmtUpdate.setString(6,UUID.randomUUID().toString());
      pstmtUpdate.executeUpdate();
      pstmtUpdate.close();
      pstmtUpdate=conn.prepareStatement(insertTraficType);
      pstmtUpdate.setLong(1,physicalNetworkId);
      pstmtUpdate.setString(2,"String_Node_Str");
      pstmtUpdate.setString(3,xenStorageLabel);
      pstmtUpdate.setString(4,null);
      pstmtUpdate.setString(5,null);
      pstmtUpdate.setString(6,UUID.randomUUID().toString());
      pstmtUpdate.executeUpdate();
      pstmtUpdate.close();
      pstmtUpdate=conn.prepareStatement(insertTraficType);
      pstmtUpdate.setLong(1,physicalNetworkId);
      pstmtUpdate.setString(2,"String_Node_Str");
      pstmtUpdate.setString(3,xenGuestLabel);
      pstmtUpdate.setString(4,kvmGuestLabel);
      pstmtUpdate.setString(5,vmwareGuestLabel);
      pstmtUpdate.setString(6,UUID.randomUUID().toString());
      pstmtUpdate.executeUpdate();
      pstmtUpdate.close();
      s_logger.debug("String_Node_Str");
      String insertPNSP="String_Node_Str" + "String_Node_Str" + "String_Node_Str"+ "String_Node_Str";
      pstmtUpdate=conn.prepareStatement(insertPNSP);
      pstmtUpdate.setString(1,UUID.randomUUID().toString());
      pstmtUpdate.setLong(2,physicalNetworkId);
      pstmtUpdate.setString(3,"String_Node_Str");
      pstmtUpdate.setString(4,"String_Node_Str");
      pstmtUpdate.setLong(5,0);
      pstmtUpdate.setInt(6,1);
      pstmtUpdate.setInt(7,1);
      pstmtUpdate.setInt(8,1);
      pstmtUpdate.setInt(9,1);
      pstmtUpdate.setInt(10,1);
      pstmtUpdate.setInt(11,1);
      pstmtUpdate.setInt(12,1);
      pstmtUpdate.setInt(13,1);
      pstmtUpdate.setInt(14,1);
      pstmtUpdate.setInt(15,1);
      pstmtUpdate.setInt(16,0);
      pstmtUpdate.executeUpdate();
      pstmtUpdate.close();
      String fetchNSPid="String_Node_Str" + physicalNetworkId;
      pstmt2=conn.prepareStatement(fetchNSPid);
      ResultSet rsNSPid=pstmt2.executeQuery();
      rsNSPid.next();
      long nspId=rsNSPid.getLong(1);
      rsSeq.close();
      pstmt2.close();
      String insertRouter="String_Node_Str" + "String_Node_Str";
      pstmtUpdate=conn.prepareStatement(insertRouter);
      pstmtUpdate.setLong(1,nspId);
      pstmtUpdate.setString(2,UUID.randomUUID().toString());
      pstmtUpdate.setString(3,"String_Node_Str");
      pstmtUpdate.setInt(4,1);
      pstmtUpdate.executeUpdate();
      pstmtUpdate.close();
      s_logger.debug("String_Node_Str");
      String updateVnet="String_Node_Str" + physicalNetworkId + "String_Node_Str"+ zoneId;
      pstmtUpdate=conn.prepareStatement(updateVnet);
      pstmtUpdate.executeUpdate();
      pstmtUpdate.close();
      s_logger.debug("String_Node_Str");
      String updateVLAN="String_Node_Str" + physicalNetworkId + "String_Node_Str"+ zoneId;
      pstmtUpdate=conn.prepareStatement(updateVLAN);
      pstmtUpdate.executeUpdate();
      pstmtUpdate.close();
      s_logger.debug("String_Node_Str");
      String updateUsrIp="String_Node_Str" + physicalNetworkId + "String_Node_Str"+ zoneId;
      pstmtUpdate=conn.prepareStatement(updateUsrIp);
      pstmtUpdate.executeUpdate();
      pstmtUpdate.close();
      s_logger.debug("String_Node_Str");
      String updateNet="String_Node_Str" + physicalNetworkId + "String_Node_Str"+ zoneId+ "String_Node_Str";
      pstmtUpdate=conn.prepareStatement(updateNet);
      pstmtUpdate.executeUpdate();
      pstmtUpdate.close();
    }
  }
 catch (  SQLException e) {
    throw new CloudRuntimeException("String_Node_Str",e);
  }
 finally {
    if (pstmtUpdate != null) {
      try {
        pstmtUpdate.close();
      }
 catch (      SQLException e) {
      }
    }
    if (rs != null) {
      try {
        rs.close();
      }
 catch (      SQLException e) {
      }
    }
    if (pstmt != null) {
      try {
        pstmt.close();
      }
 catch (      SQLException e) {
      }
    }
  }
}