Program: 125368
Project: 125368
Buggy source:
public static void fillCatalogAndSchemas(IMetadataConnection iMetadataConnection,DatabaseConnection temConnection) throws ClassNotFoundException, InstantiationException, IllegalAccessException, SQLException {
  java.sql.Connection sqlConn=null;
  try {
    MetadataFillFactory dbInstance=MetadataFillFactory.getDBInstance(iMetadataConnection);
    temConnection=(DatabaseConnection)dbInstance.fillUIConnParams(iMetadataConnection,temConnection);
    sqlConn=MetadataConnectionUtils.createConnection(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());
      }
      dbInstance.fillCatalogs(temConnection,dbMetaData,iMetadataConnection,MetadataConnectionUtils.getPackageFilter(temConnection,dbMetaData,true));
      dbInstance.fillSchemas(temConnection,dbMetaData,iMetadataConnection,MetadataConnectionUtils.getPackageFilter(temConnection,dbMetaData,false));
    }
  }
 catch (  SQLException e) {
    throw e;
  }
 finally {
    if (sqlConn != null) {
      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 {
    MetadataFillFactory dbInstance=MetadataFillFactory.getDBInstance(iMetadataConnection);
    temConnection=(DatabaseConnection)dbInstance.fillUIConnParams(iMetadataConnection,temConnection);
    sqlConn=MetadataConnectionUtils.createConnection(iMetadataConnection).getObject();
    if (!temConnection.isContextMode() && ((DatabaseConnection)iMetadataConnection.getCurrentConnection()).getUiSchema() != null) {
      temConnection.setUiSchema(((DatabaseConnection)iMetadataConnection.getCurrentConnection()).getUiSchema());
    }
    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());
      }
      dbInstance.fillCatalogs(temConnection,dbMetaData,iMetadataConnection,MetadataConnectionUtils.getPackageFilter(temConnection,dbMetaData,true));
      dbInstance.fillSchemas(temConnection,dbMetaData,iMetadataConnection,MetadataConnectionUtils.getPackageFilter(temConnection,dbMetaData,false));
    }
  }
 catch (  SQLException e) {
    throw e;
  }
 finally {
    if (sqlConn != null) {
      ConnectionUtils.closeConnection(sqlConn);
    }
    MetadataConnectionUtils.closeDerbyDriver();
  }
}