Program: 126945
Project: 126945
Buggy source:
public static void fillCatalogAndSchemas(IMetadataConnection iMetadataConnection,DatabaseConnection temConnection) throws ClassNotFoundException, InstantiationException, IllegalAccessException, SQLException {
  java.sql.Connection sqlConn=null;
  try {
    temConnection=(DatabaseConnection)MetadataFillFactory.getDBInstance().fillUIConnParams(iMetadataConnection,temConnection);
    sqlConn=MetadataConnectionUtils.checkConnection(iMetadataConnection).getObject();
    if (((DatabaseConnection)iMetadataConnection.getCurrentConnection()).getUiSchema() != null) {
      temConnection.setUiSchema(((DatabaseConnection)iMetadataConnection.getCurrentConnection()).getUiSchema());
    }
    if (((DatabaseConnection)iMetadataConnection.getCurrentConnection()).getSID() != null) {
      temConnection.setSID(((DatabaseConnection)iMetadataConnection.getCurrentConnection()).getSID());
    }
    String dbType=iMetadataConnection.getDbType();
    if (sqlConn != null) {
      DatabaseMetaData dbMetaData=null;
      if (EDatabaseTypeName.HIVE.getXmlName().equalsIgnoreCase(dbType)) {
        dbMetaData=HiveConnectionManager.getInstance().extractDatabaseMetaData(iMetadataConnection);
      }
 else {
        dbMetaData=ExtractMetaDataUtils.getInstance().getDatabaseMetaData(sqlConn,dbType,false,iMetadataConnection.getDatabase());
      }
      MetadataFillFactory.getDBInstance().fillCatalogs(temConnection,dbMetaData,iMetadataConnection,MetadataConnectionUtils.getPackageFilter(temConnection,dbMetaData,true));
      MetadataFillFactory.getDBInstance().fillSchemas(temConnection,dbMetaData,iMetadataConnection,MetadataConnectionUtils.getPackageFilter(temConnection,dbMetaData,false));
    }
  }
 catch (  SQLException e) {
    throw e;
  }
 finally {
    ConnectionUtils.closeConnection(sqlConn);
    MetadataConnectionUtils.closeDerbyDriver();
  }
}

Fixed version (ground truth):
public static void fillCatalogAndSchemas(IMetadataConnection iMetadataConnection,DatabaseConnection temConnection) throws ClassNotFoundException, InstantiationException, IllegalAccessException, SQLException {
  java.sql.Connection sqlConn=null;
  try {
    temConnection=(DatabaseConnection)MetadataFillFactory.getDBInstance().fillUIConnParams(iMetadataConnection,temConnection);
    sqlConn=MetadataConnectionUtils.checkConnection(iMetadataConnection).getObject();
    if (((DatabaseConnection)iMetadataConnection.getCurrentConnection()).getUiSchema() != null) {
      temConnection.setUiSchema(((DatabaseConnection)iMetadataConnection.getCurrentConnection()).getUiSchema());
    }
    if (((DatabaseConnection)iMetadataConnection.getCurrentConnection()).getSID() != null) {
      temConnection.setSID(((DatabaseConnection)iMetadataConnection.getCurrentConnection()).getSID());
    }
    String dbType=iMetadataConnection.getDbType();
    if (sqlConn != null) {
      DatabaseMetaData dbMetaData=null;
      if (EDatabaseTypeName.HIVE.getXmlName().equalsIgnoreCase(dbType)) {
        dbMetaData=HiveConnectionManager.getInstance().extractDatabaseMetaData(iMetadataConnection);
      }
 else {
        dbMetaData=ExtractMetaDataUtils.getInstance().getDatabaseMetaData(sqlConn,dbType,false,iMetadataConnection.getDatabase());
      }
      MetadataFillFactory.getDBInstance().fillCatalogs(temConnection,dbMetaData,iMetadataConnection,MetadataConnectionUtils.getPackageFilter(temConnection,dbMetaData,true));
      MetadataFillFactory.getDBInstance().fillSchemas(temConnection,dbMetaData,iMetadataConnection,MetadataConnectionUtils.getPackageFilter(temConnection,dbMetaData,false));
    }
  }
 catch (  SQLException e) {
    throw e;
  }
 finally {
    if (sqlConn != null) {
      ConnectionUtils.closeConnection(sqlConn);
    }
    MetadataConnectionUtils.closeDerbyDriver();
  }
}