Program: 126952
Project: 126952
Buggy source:
/** 
 * DOC xqliu Comment method "fillDbConnectionInformation".
 * @param dbConn
 * @return
 */
public static DatabaseConnection fillDbConnectionInformation(DatabaseConnection dbConn,IMetadataConnection metadataConnection){
  boolean noStructureExists=ConnectionHelper.getAllCatalogs(dbConn).isEmpty() && ConnectionHelper.getAllSchemas(dbConn).isEmpty();
  java.sql.Connection sqlConn=null;
  try {
    if (noStructureExists) {
      IMetadataConnection metaConnection=metadataConnection;
      if (metadataConnection == null) {
        metaConnection=ConvertionHelper.convert(dbConn);
      }
      dbConn=(DatabaseConnection)MetadataFillFactory.getDBInstance().fillUIConnParams(metaConnection,dbConn);
      sqlConn=MetadataConnectionUtils.checkConnection(metaConnection).getObject();
      if (sqlConn != null) {
        DatabaseMetaData databaseMetaData=null;
        if (EDatabaseTypeName.HIVE.getXmlName().equalsIgnoreCase(metaConnection.getDbType())) {
          databaseMetaData=HiveConnectionManager.getInstance().extractDatabaseMetaData(metaConnection);
        }
 else {
          databaseMetaData=ExtractMetaDataUtils.getInstance().getDatabaseMetaData(sqlConn,dbConn,false);
        }
        if (sqlConn != null) {
          MetadataFillFactory.getDBInstance().fillCatalogs(dbConn,databaseMetaData,metaConnection,MetadataConnectionUtils.getPackageFilter(dbConn,databaseMetaData,true));
          MetadataFillFactory.getDBInstance().fillSchemas(dbConn,databaseMetaData,metaConnection,MetadataConnectionUtils.getPackageFilter(dbConn,databaseMetaData,false));
        }
      }
    }
  }
 catch (  Exception e) {
    log.error(e,e);
  }
 finally {
    boolean hsql=ConnectionUtils.isHsql(metadataConnection.getUrl());
    if (hsql) {
      ConnectionUtils.closeConnection(sqlConn);
    }
    closeDerbyDriver();
  }
  return dbConn;
}

Fixed version (ground truth):
/** 
 * DOC xqliu Comment method "fillDbConnectionInformation".
 * @param dbConn
 * @return
 */
public static DatabaseConnection fillDbConnectionInformation(DatabaseConnection dbConn,IMetadataConnection metadataConnection){
  boolean noStructureExists=ConnectionHelper.getAllCatalogs(dbConn).isEmpty() && ConnectionHelper.getAllSchemas(dbConn).isEmpty();
  java.sql.Connection sqlConn=null;
  try {
    if (noStructureExists) {
      IMetadataConnection metaConnection=metadataConnection;
      if (metadataConnection == null) {
        metaConnection=ConvertionHelper.convert(dbConn);
      }
      dbConn=(DatabaseConnection)MetadataFillFactory.getDBInstance().fillUIConnParams(metaConnection,dbConn);
      sqlConn=MetadataConnectionUtils.checkConnection(metaConnection).getObject();
      if (sqlConn != null) {
        DatabaseMetaData databaseMetaData=null;
        if (EDatabaseTypeName.HIVE.getXmlName().equalsIgnoreCase(metaConnection.getDbType())) {
          databaseMetaData=HiveConnectionManager.getInstance().extractDatabaseMetaData(metaConnection);
        }
 else {
          databaseMetaData=ExtractMetaDataUtils.getInstance().getDatabaseMetaData(sqlConn,dbConn,false);
        }
        if (sqlConn != null) {
          MetadataFillFactory.getDBInstance().fillCatalogs(dbConn,databaseMetaData,metaConnection,MetadataConnectionUtils.getPackageFilter(dbConn,databaseMetaData,true));
          MetadataFillFactory.getDBInstance().fillSchemas(dbConn,databaseMetaData,metaConnection,MetadataConnectionUtils.getPackageFilter(dbConn,databaseMetaData,false));
        }
      }
    }
  }
 catch (  Exception e) {
    log.error(e,e);
  }
 finally {
    boolean hsql=ConnectionUtils.isHsql(metadataConnection.getUrl());
    if (hsql && sqlConn != null) {
      ConnectionUtils.closeConnection(sqlConn);
    }
    closeDerbyDriver();
  }
  return dbConn;
}