Program: 84039
Project: 84039
Buggy source:
protected void readIndexes(DatabaseSnapshot snapshot,String schema,DatabaseMetaData databaseMetaData) throws DatabaseException, SQLException {
  Database database=snapshot.getDatabase();
  updateListeners("String_Node_Str" + database.toString() + "String_Node_Str");
  for (  Table table : snapshot.getTables()) {
    ResultSet rs;
    Statement statement=null;
    if (database instanceof OracleDatabase) {
      statement=((JdbcConnection)database.getConnection()).getUnderlyingConnection().createStatement();
      String sql="String_Node_Str" + database.convertRequestedSchemaToSchema(schema) + "String_Node_Str"+ table.getName()+ "String_Node_Str";
      rs=statement.executeQuery(sql);
    }
 else {
      rs=databaseMetaData.getIndexInfo(database.convertRequestedSchemaToCatalog(schema),database.convertRequestedSchemaToSchema(schema),table.getName(),false,true);
    }
    Map<String,Index> indexMap=new HashMap<String,Index>();
    while (rs.next()) {
      String indexName=convertFromDatabaseName(rs.getString("String_Node_Str"));
      if (database instanceof InformixDatabase && indexName.startsWith("String_Node_Str")) {
        indexName="String_Node_Str" + indexName.substring(1);
      }
      short type=rs.getShort("String_Node_Str");
      boolean nonUnique=true;
      try {
        nonUnique=rs.getBoolean("String_Node_Str");
      }
 catch (      SQLException e) {
      }
      String columnName=convertFromDatabaseName(rs.getString("String_Node_Str"));
      short position=rs.getShort("String_Node_Str");
      if (database instanceof InformixDatabase && type != DatabaseMetaData.tableIndexStatistic && position == 0) {
        System.out.println(this.getClass().getName() + "String_Node_Str" + ++position);
      }
      String filterCondition=rs.getString("String_Node_Str");
      if (type == DatabaseMetaData.tableIndexStatistic) {
        continue;
      }
      if (columnName == null) {
        continue;
      }
      Index indexInformation;
      if (indexMap.containsKey(indexName)) {
        indexInformation=indexMap.get(indexName);
      }
 else {
        indexInformation=new Index();
        indexInformation.setTable(table);
        indexInformation.setName(indexName);
        indexInformation.setUnique(!nonUnique);
        indexInformation.setFilterCondition(filterCondition);
        indexMap.put(indexName,indexInformation);
      }
      for (int i=indexInformation.getColumns().size(); i < position; i++) {
        indexInformation.getColumns().add(null);
      }
      indexInformation.getColumns().set(position - 1,columnName);
    }
    for (    Map.Entry<String,Index> entry : indexMap.entrySet()) {
      snapshot.getIndexes().add(entry.getValue());
    }
    rs.close();
    if (statement != null) {
      statement.close();
    }
  }
  Set<Index> indexesToRemove=new HashSet<Index>();
  for (  Index index : snapshot.getIndexes()) {
    for (    PrimaryKey pk : snapshot.getPrimaryKeys()) {
      if (index.getTable().getName().equalsIgnoreCase(pk.getTable().getName()) && index.getColumnNames().equals(pk.getColumnNames())) {
        index.addAssociatedWith(Index.MARK_PRIMARY_KEY);
      }
    }
    for (    ForeignKey fk : snapshot.getForeignKeys()) {
      if (index.getTable().getName().equalsIgnoreCase(fk.getForeignKeyTable().getName()) && index.getColumnNames().equals(fk.getForeignKeyColumns())) {
        index.addAssociatedWith(Index.MARK_FOREIGN_KEY);
      }
    }
    for (    UniqueConstraint uc : snapshot.getUniqueConstraints()) {
      if (index.getTable().getName().equalsIgnoreCase(uc.getTable().getName()) && index.getColumnNames().equals(uc.getColumnNames())) {
        index.addAssociatedWith(Index.MARK_UNIQUE_CONSTRAINT);
      }
    }
  }
  snapshot.getIndexes().removeAll(indexesToRemove);
}

Fixed version (ground truth):
protected void readIndexes(DatabaseSnapshot snapshot,String schema,DatabaseMetaData databaseMetaData) throws DatabaseException, SQLException {
  Database database=snapshot.getDatabase();
  updateListeners("String_Node_Str" + database.toString() + "String_Node_Str");
  for (  Table table : snapshot.getTables()) {
    ResultSet rs=null;
    Statement statement=null;
    try {
      if (database instanceof OracleDatabase) {
        statement=((JdbcConnection)database.getConnection()).getUnderlyingConnection().createStatement();
        String sql="String_Node_Str" + database.convertRequestedSchemaToSchema(schema) + "String_Node_Str"+ table.getName()+ "String_Node_Str";
        rs=statement.executeQuery(sql);
      }
 else {
        rs=databaseMetaData.getIndexInfo(database.convertRequestedSchemaToCatalog(schema),database.convertRequestedSchemaToSchema(schema),table.getName(),false,true);
      }
      Map<String,Index> indexMap=new HashMap<String,Index>();
      while (rs.next()) {
        String indexName=convertFromDatabaseName(rs.getString("String_Node_Str"));
        if (database instanceof InformixDatabase && indexName.startsWith("String_Node_Str")) {
          indexName="String_Node_Str" + indexName.substring(1);
        }
        short type=rs.getShort("String_Node_Str");
        boolean nonUnique=true;
        try {
          nonUnique=rs.getBoolean("String_Node_Str");
        }
 catch (        SQLException e) {
        }
        String columnName=convertFromDatabaseName(rs.getString("String_Node_Str"));
        short position=rs.getShort("String_Node_Str");
        if (database instanceof InformixDatabase && type != DatabaseMetaData.tableIndexStatistic && position == 0) {
          System.out.println(this.getClass().getName() + "String_Node_Str" + ++position);
        }
        String filterCondition=rs.getString("String_Node_Str");
        if (type == DatabaseMetaData.tableIndexStatistic) {
          continue;
        }
        if (columnName == null) {
          continue;
        }
        Index indexInformation;
        if (indexMap.containsKey(indexName)) {
          indexInformation=indexMap.get(indexName);
        }
 else {
          indexInformation=new Index();
          indexInformation.setTable(table);
          indexInformation.setName(indexName);
          indexInformation.setUnique(!nonUnique);
          indexInformation.setFilterCondition(filterCondition);
          indexMap.put(indexName,indexInformation);
        }
        for (int i=indexInformation.getColumns().size(); i < position; i++) {
          indexInformation.getColumns().add(null);
        }
        indexInformation.getColumns().set(position - 1,columnName);
      }
      for (      Map.Entry<String,Index> entry : indexMap.entrySet()) {
        snapshot.getIndexes().add(entry.getValue());
      }
    }
  finally {
      if (rs != null) {
        try {
          rs.close();
        }
 catch (        SQLException ignored) {
        }
      }
      if (statement != null) {
        try {
          statement.close();
        }
 catch (        SQLException ignored) {
        }
      }
    }
  }
  Set<Index> indexesToRemove=new HashSet<Index>();
  for (  Index index : snapshot.getIndexes()) {
    for (    PrimaryKey pk : snapshot.getPrimaryKeys()) {
      if (index.getTable().getName().equalsIgnoreCase(pk.getTable().getName()) && index.getColumnNames().equals(pk.getColumnNames())) {
        index.addAssociatedWith(Index.MARK_PRIMARY_KEY);
      }
    }
    for (    ForeignKey fk : snapshot.getForeignKeys()) {
      if (index.getTable().getName().equalsIgnoreCase(fk.getForeignKeyTable().getName()) && index.getColumnNames().equals(fk.getForeignKeyColumns())) {
        index.addAssociatedWith(Index.MARK_FOREIGN_KEY);
      }
    }
    for (    UniqueConstraint uc : snapshot.getUniqueConstraints()) {
      if (index.getTable().getName().equalsIgnoreCase(uc.getTable().getName()) && index.getColumnNames().equals(uc.getColumnNames())) {
        index.addAssociatedWith(Index.MARK_UNIQUE_CONSTRAINT);
      }
    }
  }
  snapshot.getIndexes().removeAll(indexesToRemove);
}