Program: 107070
Project: 107070
Buggy source:
protected void upgradeBasicUserVms(Connection conn,long domainRouterId,long networkId,String gateway,String vnet) throws SQLException {
  PreparedStatement pstmt=conn.prepareStatement("String_Node_Str");
  pstmt.setLong(1,domainRouterId);
  ResultSet rs=pstmt.executeQuery();
  List<Object[]> vms=new ArrayList<Object[]>();
  while (rs.next()) {
    Object[] vm=new Object[10];
    vm[0]=rs.getLong(1);
    vm[1]=rs.getString(2);
    vm[2]=rs.getString(3);
    vm[3]=rs.getString(4);
    vm[4]=rs.getString(5);
    vm[5]=rs.getString(6);
    vms.add(vm);
  }
  rs.close();
  pstmt.close();
  s_logger.debug("String_Node_Str" + vms.size() + "String_Node_Str"+ domainRouterId);
  int count=0;
  for (  Object[] vm : vms) {
    String state=(String)vm[4];
    boolean running=false;
    if (state.equals("String_Node_Str") || state.equals("String_Node_Str") || state.equals("String_Node_Str")) {
      running=true;
      count++;
    }
    insertNic(conn,networkId,(Long)vm[0],running,(String)vm[1],(String)vm[2],(String)vm[3],"String_Node_Str",gateway,vnet,"String_Node_Str",true,0,"String_Node_Str",null);
  }
  pstmt=conn.prepareStatement("String_Node_Str");
  pstmt.setLong(1,domainRouterId);
  rs=pstmt.executeQuery();
  rs.next();
  String state=rs.getString(1);
  if (state.equals("String_Node_Str") || state.equals("String_Node_Str") || state.equals("String_Node_Str")) {
    count++;
  }
  rs.close();
  pstmt.close();
  pstmt=conn.prepareStatement("String_Node_Str");
  pstmt.setLong(1,count);
  if (count == 0) {
    pstmt.setBoolean(2,false);
  }
 else {
    pstmt.setBoolean(2,true);
  }
  pstmt.setLong(3,networkId);
  pstmt.executeUpdate();
  pstmt.close();
}

Fixed version (ground truth):
protected void upgradeBasicUserVms(Connection conn,long domainRouterId,long networkId,String gateway,String vnet) throws SQLException {
  PreparedStatement pstmt=conn.prepareStatement("String_Node_Str");
  pstmt.setLong(1,domainRouterId);
  ResultSet rs=pstmt.executeQuery();
  List<Object[]> vms=new ArrayList<Object[]>();
  while (rs.next()) {
    Object[] vm=new Object[10];
    vm[0]=rs.getLong(1);
    vm[1]=rs.getString(2);
    vm[2]=rs.getString(3);
    vm[3]=rs.getString(4);
    vm[4]=rs.getString(5);
    vm[5]=rs.getString(6);
    vms.add(vm);
  }
  rs.close();
  pstmt.close();
  s_logger.debug("String_Node_Str" + vms.size() + "String_Node_Str"+ domainRouterId);
  int count=0;
  for (  Object[] vm : vms) {
    String state=(String)vm[4];
    boolean running=false;
    if (state.equals("String_Node_Str") || state.equals("String_Node_Str") || state.equals("String_Node_Str")) {
      running=true;
      String type=(String)vm[5];
      if (type.equalsIgnoreCase("String_Node_Str")) {
        count++;
      }
    }
    insertNic(conn,networkId,(Long)vm[0],running,(String)vm[1],(String)vm[2],(String)vm[3],"String_Node_Str",gateway,vnet,"String_Node_Str",true,0,"String_Node_Str",null);
  }
  pstmt=conn.prepareStatement("String_Node_Str");
  pstmt.setLong(1,domainRouterId);
  rs=pstmt.executeQuery();
  rs.next();
  String state=rs.getString(1);
  if (state.equals("String_Node_Str") || state.equals("String_Node_Str") || state.equals("String_Node_Str")) {
    count++;
  }
  rs.close();
  pstmt.close();
  Long originalNicsCount=0L;
  pstmt=conn.prepareStatement("String_Node_Str");
  pstmt.setLong(1,networkId);
  ResultSet originalCountRs=pstmt.executeQuery();
  if (originalCountRs.next()) {
    originalNicsCount=originalCountRs.getLong(1);
  }
  Long resultCount=originalNicsCount + count;
  originalCountRs.close();
  pstmt.close();
  pstmt=conn.prepareStatement("String_Node_Str");
  pstmt.setLong(1,resultCount);
  if (count == 0) {
    pstmt.setBoolean(2,false);
  }
 else {
    pstmt.setBoolean(2,true);
  }
  pstmt.setLong(3,networkId);
  pstmt.executeUpdate();
  pstmt.close();
}