Program: 84109
Project: 84109
Buggy source:
public HibernateDatabaseSnapshot(HibernateDatabase database) throws JDBCException {
  try {
    Configuration cfg=database.createConfiguration();
    cfg.configure(database.getConfigFile());
    this.database=database;
    Dialect dialect=new HibernateGenericDialect(cfg.getProperty("String_Node_Str"));
    cfg.buildMappings();
    Mapping mapping=cfg.buildMapping();
    Iterator tableMappings=cfg.getTableMappings();
    while (tableMappings.hasNext()) {
      org.hibernate.mapping.Table hibernateTable=(org.hibernate.mapping.Table)tableMappings.next();
      if (hibernateTable.isPhysicalTable()) {
        Table table=new Table(hibernateTable.getName());
        System.out.println("String_Node_Str" + table.getName());
        tablesMap.put(table.getName(),table);
        Iterator columnIterator=hibernateTable.getColumnIterator();
        while (columnIterator.hasNext()) {
          org.hibernate.mapping.Column hibernateColumn=(org.hibernate.mapping.Column)columnIterator.next();
          Column column=new Column();
          column.setName(hibernateColumn.getName());
          column.setDataType(hibernateColumn.getSqlTypeCode(mapping));
          if (column.isNumeric()) {
            column.setColumnSize(hibernateColumn.getPrecision());
          }
 else {
            column.setColumnSize(hibernateColumn.getLength());
          }
          column.setDecimalDigits(hibernateColumn.getScale());
          column.setDefaultValue(hibernateColumn.getDefaultValue());
          column.setNullable(hibernateColumn.isNullable());
          column.setPrimaryKey(isPrimaryKey(hibernateTable,hibernateColumn));
          column.setTable(table);
          column.setTypeName(hibernateColumn.getSqlType(dialect,mapping).replaceFirst("String_Node_Str","String_Node_Str"));
          column.setUnique(hibernateColumn.isUnique());
          column.setCertainDataType(false);
          columnsMap.put(table.getName() + "String_Node_Str" + column.getName(),column);
          table.getColumns().add(column);
        }
        Iterator indexIterator=hibernateTable.getIndexIterator();
        while (indexIterator.hasNext()) {
          org.hibernate.mapping.Index hibernateIndex=(org.hibernate.mapping.Index)indexIterator.next();
          Index index=new Index();
          index.setTable(table);
          index.setName(hibernateIndex.getName());
          columnIterator=hibernateIndex.getColumnIterator();
          while (columnIterator.hasNext()) {
            org.hibernate.mapping.Column hibernateColumn=(org.hibernate.mapping.Column)columnIterator.next();
            index.getColumns().add(hibernateColumn.getName());
          }
          indexes.add(index);
        }
        org.hibernate.mapping.PrimaryKey hibernatePrimaryKey=hibernateTable.getPrimaryKey();
        if (hibernatePrimaryKey != null) {
          PrimaryKey pk=new PrimaryKey();
          pk.setName(hibernatePrimaryKey.getName());
          pk.setTable(table);
          for (          Object hibernateColumn : hibernatePrimaryKey.getColumns()) {
            pk.getColumnNamesAsList().add(((org.hibernate.mapping.Column)hibernateColumn).getName());
          }
          primaryKeys.add(pk);
        }
      }
    }
    this.tables=new HashSet<Table>(tablesMap.values());
    this.columns=new HashSet<Column>(columnsMap.values());
    tableMappings=cfg.getTableMappings();
    while (tableMappings.hasNext()) {
      org.hibernate.mapping.Table hibernateTable=(org.hibernate.mapping.Table)tableMappings.next();
      if (hibernateTable.isPhysicalTable()) {
        Iterator fkIterator=hibernateTable.getForeignKeyIterator();
        while (fkIterator.hasNext()) {
          org.hibernate.mapping.ForeignKey hibernateForeignKey=(org.hibernate.mapping.ForeignKey)fkIterator.next();
          if (hibernateForeignKey.getTable() != null && hibernateForeignKey.getReferencedTable() != null && hibernateForeignKey.isPhysicalConstraint()) {
            ForeignKey fk=new ForeignKey();
            fk.setName(hibernateForeignKey.getName());
            fk.setForeignKeyTable(getTable(hibernateForeignKey.getTable().getName()));
            List<String> fkColumns=new ArrayList<String>();
            for (            Object column : hibernateForeignKey.getColumns()) {
              fkColumns.add(((org.hibernate.mapping.Column)column).getName());
            }
            fk.setForeignKeyColumns(StringUtils.join(fkColumns,"String_Node_Str"));
            fk.setPrimaryKeyTable(getTable(hibernateForeignKey.getReferencedTable().getName()));
            fkColumns=new ArrayList<String>();
            for (            Object column : hibernateForeignKey.getReferencedColumns()) {
              fkColumns.add(((org.hibernate.mapping.Column)column).getName());
            }
            if (fkColumns.size() == 0) {
              for (              Object column : hibernateForeignKey.getReferencedTable().getPrimaryKey().getColumns()) {
                fkColumns.add(((org.hibernate.mapping.Column)column).getName());
              }
            }
            fk.setPrimaryKeyColumns(StringUtils.join(fkColumns,"String_Node_Str"));
            foreignKeys.add(fk);
          }
        }
      }
    }
  }
 catch (  Exception e) {
    throw new JDBCException(e);
  }
}

Fixed version (ground truth):
public HibernateDatabaseSnapshot(HibernateDatabase database) throws JDBCException {
  try {
    Configuration cfg=database.createConfiguration();
    cfg.configure(database.getConfigFile());
    this.database=database;
    Dialect dialect=new HibernateGenericDialect(cfg.getProperty("String_Node_Str"));
    cfg.buildMappings();
    Mapping mapping=cfg.buildMapping();
    Iterator tableMappings=cfg.getTableMappings();
    while (tableMappings.hasNext()) {
      org.hibernate.mapping.Table hibernateTable=(org.hibernate.mapping.Table)tableMappings.next();
      if (hibernateTable.isPhysicalTable()) {
        Table table=new Table(hibernateTable.getName());
        System.out.println("String_Node_Str" + table.getName());
        tablesMap.put(table.getName(),table);
        Iterator columnIterator=hibernateTable.getColumnIterator();
        while (columnIterator.hasNext()) {
          org.hibernate.mapping.Column hibernateColumn=(org.hibernate.mapping.Column)columnIterator.next();
          Column column=new Column();
          column.setName(hibernateColumn.getName());
          column.setDataType(hibernateColumn.getSqlTypeCode(mapping));
          if (column.isNumeric()) {
            column.setColumnSize(hibernateColumn.getPrecision());
          }
 else {
            column.setColumnSize(hibernateColumn.getLength());
          }
          column.setDecimalDigits(hibernateColumn.getScale());
          column.setDefaultValue(hibernateColumn.getDefaultValue());
          column.setNullable(hibernateColumn.isNullable());
          column.setPrimaryKey(isPrimaryKey(hibernateTable,hibernateColumn));
          column.setTable(table);
          column.setTypeName(hibernateColumn.getSqlType(dialect,mapping).replaceFirst("String_Node_Str","String_Node_Str"));
          column.setUnique(hibernateColumn.isUnique());
          column.setCertainDataType(false);
          columnsMap.put(table.getName() + "String_Node_Str" + column.getName(),column);
          table.getColumns().add(column);
        }
        Iterator indexIterator=hibernateTable.getIndexIterator();
        while (indexIterator.hasNext()) {
          org.hibernate.mapping.Index hibernateIndex=(org.hibernate.mapping.Index)indexIterator.next();
          Index index=new Index();
          index.setTable(table);
          index.setName(hibernateIndex.getName());
          columnIterator=hibernateIndex.getColumnIterator();
          while (columnIterator.hasNext()) {
            org.hibernate.mapping.Column hibernateColumn=(org.hibernate.mapping.Column)columnIterator.next();
            index.getColumns().add(hibernateColumn.getName());
          }
          indexes.add(index);
        }
        Iterator uniqueIterator=hibernateTable.getUniqueKeyIterator();
        while (uniqueIterator.hasNext()) {
          org.hibernate.mapping.UniqueKey hiberateUnique=(org.hibernate.mapping.UniqueKey)uniqueIterator.next();
          Index index=new Index();
          index.setTable(table);
          index.setName(hiberateUnique.getName());
          columnIterator=hiberateUnique.getColumnIterator();
          while (columnIterator.hasNext()) {
            org.hibernate.mapping.Column hibernateColumn=(org.hibernate.mapping.Column)columnIterator.next();
            index.getColumns().add(hibernateColumn.getName());
          }
          indexes.add(index);
        }
        org.hibernate.mapping.PrimaryKey hibernatePrimaryKey=hibernateTable.getPrimaryKey();
        if (hibernatePrimaryKey != null) {
          PrimaryKey pk=new PrimaryKey();
          pk.setName(hibernatePrimaryKey.getName());
          pk.setTable(table);
          for (          Object hibernateColumn : hibernatePrimaryKey.getColumns()) {
            pk.getColumnNamesAsList().add(((org.hibernate.mapping.Column)hibernateColumn).getName());
          }
          primaryKeys.add(pk);
        }
      }
    }
    this.tables=new HashSet<Table>(tablesMap.values());
    this.columns=new HashSet<Column>(columnsMap.values());
    tableMappings=cfg.getTableMappings();
    while (tableMappings.hasNext()) {
      org.hibernate.mapping.Table hibernateTable=(org.hibernate.mapping.Table)tableMappings.next();
      if (hibernateTable.isPhysicalTable()) {
        Iterator fkIterator=hibernateTable.getForeignKeyIterator();
        while (fkIterator.hasNext()) {
          org.hibernate.mapping.ForeignKey hibernateForeignKey=(org.hibernate.mapping.ForeignKey)fkIterator.next();
          if (hibernateForeignKey.getTable() != null && hibernateForeignKey.getReferencedTable() != null && hibernateForeignKey.isPhysicalConstraint()) {
            ForeignKey fk=new ForeignKey();
            fk.setName(hibernateForeignKey.getName());
            fk.setForeignKeyTable(getTable(hibernateForeignKey.getTable().getName()));
            List<String> fkColumns=new ArrayList<String>();
            for (            Object column : hibernateForeignKey.getColumns()) {
              fkColumns.add(((org.hibernate.mapping.Column)column).getName());
            }
            fk.setForeignKeyColumns(StringUtils.join(fkColumns,"String_Node_Str"));
            fk.setPrimaryKeyTable(getTable(hibernateForeignKey.getReferencedTable().getName()));
            fkColumns=new ArrayList<String>();
            for (            Object column : hibernateForeignKey.getReferencedColumns()) {
              fkColumns.add(((org.hibernate.mapping.Column)column).getName());
            }
            if (fkColumns.size() == 0) {
              for (              Object column : hibernateForeignKey.getReferencedTable().getPrimaryKey().getColumns()) {
                fkColumns.add(((org.hibernate.mapping.Column)column).getName());
              }
            }
            fk.setPrimaryKeyColumns(StringUtils.join(fkColumns,"String_Node_Str"));
            foreignKeys.add(fk);
          }
        }
      }
    }
  }
 catch (  Exception e) {
    throw new JDBCException(e);
  }
}