Program: 118002
Project: 118002
Buggy source:
public ArrayList<InputTable> prepareInputTables(List<IOConnection> inputConnections,ExternalMapperData externalData){
  ArrayList<InputTable> inputDataMapTables=new ArrayList<InputTable>();
  ArrayList<IOConnection> remainingConnections=new ArrayList<IOConnection>(inputConnections);
  if (externalData == null || externalData.getInputTables().size() == 0) {
    for (    IOConnection connection : inputConnections) {
      InputTable inputTable=new InputTable(this.mapperManager,connection,connection.getName());
      inputTable.initFromExternalData(null);
      inputDataMapTables.add(inputTable);
    }
  }
 else {
    Map<String,IOConnection> nameToInputConnection=new HashMap<String,IOConnection>();
    for (    IOConnection connection : inputConnections) {
      nameToInputConnection.put(connection.getName(),connection);
    }
    for (    ExternalMapperTable persistentTable : externalData.getInputTables()) {
      IOConnection connection=nameToInputConnection.get(persistentTable.getName());
      if (connection != null) {
        InputTable inputTable=new InputTable(this.mapperManager,connection,connection.getName());
        inputTable.initFromExternalData(persistentTable);
        inputDataMapTables.add(inputTable);
        remainingConnections.remove(connection);
        if (EConnectionType.FLOW_MAIN == connection.getConnectionType()) {
          inputTable.setActivateCondensedTool(false);
          inputTable.setPersistent(false);
        }
      }
    }
    for (    IOConnection connection : remainingConnections) {
      InputTable inputTable=new InputTable(this.mapperManager,connection,connection.getName());
      inputTable.initFromExternalData(null);
      inputDataMapTables.add(inputTable);
      if (EConnectionType.FLOW_MAIN == connection.getConnectionType()) {
        inputTable.setActivateCondensedTool(false);
        inputTable.setPersistent(false);
      }
    }
  }
  Collections.sort(inputDataMapTables,new Comparator<InputTable>(){
    public int compare(    InputTable o1,    InputTable o2){
      if (o1.isMainConnection()) {
        return -1;
      }
 else       if (o2.isMainConnection()) {
        return 1;
      }
      return 0;
    }
  }
);
  return inputDataMapTables;
}

Fixed version (ground truth):
public ArrayList<InputTable> prepareInputTables(List<IOConnection> inputConnections,ExternalMapperData externalData){
  ArrayList<InputTable> inputDataMapTables=new ArrayList<InputTable>();
  ArrayList<IOConnection> remainingConnections=new ArrayList<IOConnection>(inputConnections);
  if (externalData == null || externalData.getInputTables().size() == 0) {
    for (    IOConnection connection : inputConnections) {
      InputTable inputTable=new InputTable(this.mapperManager,connection,connection.getName());
      inputTable.initFromExternalData(null);
      if (EConnectionType.FLOW_MAIN != connection.getConnectionType()) {
        inputTable.setMatchingMode(TMAP_MATCHING_MODE.ALL_ROWS);
      }
      inputDataMapTables.add(inputTable);
    }
  }
 else {
    Map<String,IOConnection> nameToInputConnection=new HashMap<String,IOConnection>();
    for (    IOConnection connection : inputConnections) {
      nameToInputConnection.put(connection.getName(),connection);
    }
    for (    ExternalMapperTable persistentTable : externalData.getInputTables()) {
      IOConnection connection=nameToInputConnection.get(persistentTable.getName());
      if (connection != null) {
        InputTable inputTable=new InputTable(this.mapperManager,connection,connection.getName());
        inputTable.initFromExternalData(persistentTable);
        inputDataMapTables.add(inputTable);
        remainingConnections.remove(connection);
        if (EConnectionType.FLOW_MAIN == connection.getConnectionType()) {
          inputTable.setActivateCondensedTool(false);
          inputTable.setPersistent(false);
        }
      }
    }
    for (    IOConnection connection : remainingConnections) {
      InputTable inputTable=new InputTable(this.mapperManager,connection,connection.getName());
      inputTable.initFromExternalData(null);
      inputDataMapTables.add(inputTable);
      if (EConnectionType.FLOW_MAIN == connection.getConnectionType()) {
        inputTable.setActivateCondensedTool(false);
        inputTable.setPersistent(false);
      }
 else {
        inputTable.setMatchingMode(TMAP_MATCHING_MODE.ALL_ROWS);
      }
    }
  }
  Collections.sort(inputDataMapTables,new Comparator<InputTable>(){
    public int compare(    InputTable o1,    InputTable o2){
      if (o1.isMainConnection()) {
        return -1;
      }
 else       if (o2.isMainConnection()) {
        return 1;
      }
      return 0;
    }
  }
);
  return inputDataMapTables;
}