Program: 126955
Project: 126955
Buggy source:
private void updatePackage(IMetadataConnection metadataConnection){
  if (metadataConnection == null) {
    return;
  }
  Driver derbyDriver=null;
  Connection sqlConn=null;
  ExtractMetaDataUtils extractMeta=ExtractMetaDataUtils.getInstance();
  String dbType=metadataconnection.getDbType();
  DatabaseConnection dbConn=(DatabaseConnection)metadataconnection.getCurrentConnection();
  if (EDatabaseTypeName.HIVE.getXmlName().equalsIgnoreCase(dbType)) {
    DatabaseMetaData dm=null;
    try {
      dm=HiveConnectionManager.getInstance().extractDatabaseMetaData(metadataConnection);
      MetadataFillFactory.getDBInstance().fillCatalogs(dbConn,dm,metadataConnection,MetadataConnectionUtils.getPackageFilter(dbConn,dm,true));
      MetadataFillFactory.getDBInstance().fillSchemas(dbConn,dm,metadataConnection,MetadataConnectionUtils.getPackageFilter(dbConn,dm,false));
    }
 catch (    ClassNotFoundException e) {
      e.printStackTrace();
    }
catch (    InstantiationException e) {
      e.printStackTrace();
    }
catch (    IllegalAccessException e) {
      e.printStackTrace();
    }
catch (    SQLException e) {
      e.printStackTrace();
    }
  }
 else {
    List list=MetadataConnectionUtils.getConnection(metadataconnection);
    for (int i=0; i < list.size(); i++) {
      if (list.get(i) instanceof Driver) {
        String driverClass=metadataconnection.getDriverClass();
        if (MetadataConnectionUtils.isDerbyRelatedDb(driverClass,dbType)) {
          derbyDriver=(Driver)list.get(i);
        }
      }
      if (list.get(i) instanceof java.sql.Connection) {
        sqlConn=(java.sql.Connection)list.get(i);
      }
    }
    try {
      if (sqlConn != null) {
        DatabaseMetaData dm=extractMeta.getDatabaseMetaData(sqlConn,dbType,false,metadataconnection.getDatabase());
        MetadataFillFactory.getDBInstance().fillCatalogs(dbConn,dm,MetadataConnectionUtils.getPackageFilter(dbConn,dm,true));
        MetadataFillFactory.getDBInstance().fillSchemas(dbConn,dm,MetadataConnectionUtils.getPackageFilter(dbConn,dm,false));
      }
    }
 catch (    Exception e) {
      ExceptionHandler.process(e);
    }
 finally {
      ConnectionUtils.closeConnection(sqlConn);
      if (derbyDriver != null) {
        try {
          derbyDriver.connect("String_Node_Str",null);
        }
 catch (        SQLException e) {
        }
      }
    }
  }
}

Fixed version (ground truth):
private void updatePackage(IMetadataConnection metadataConnection){
  if (metadataConnection == null) {
    return;
  }
  Driver derbyDriver=null;
  Connection sqlConn=null;
  ExtractMetaDataUtils extractMeta=ExtractMetaDataUtils.getInstance();
  String dbType=metadataconnection.getDbType();
  DatabaseConnection dbConn=(DatabaseConnection)metadataconnection.getCurrentConnection();
  if (EDatabaseTypeName.HIVE.getXmlName().equalsIgnoreCase(dbType)) {
    DatabaseMetaData dm=null;
    try {
      dm=HiveConnectionManager.getInstance().extractDatabaseMetaData(metadataConnection);
      MetadataFillFactory.getDBInstance().fillCatalogs(dbConn,dm,metadataConnection,MetadataConnectionUtils.getPackageFilter(dbConn,dm,true));
      MetadataFillFactory.getDBInstance().fillSchemas(dbConn,dm,metadataConnection,MetadataConnectionUtils.getPackageFilter(dbConn,dm,false));
    }
 catch (    ClassNotFoundException e) {
      e.printStackTrace();
    }
catch (    InstantiationException e) {
      e.printStackTrace();
    }
catch (    IllegalAccessException e) {
      e.printStackTrace();
    }
catch (    SQLException e) {
      e.printStackTrace();
    }
  }
 else {
    List list=MetadataConnectionUtils.getConnection(metadataconnection);
    for (int i=0; i < list.size(); i++) {
      if (list.get(i) instanceof Driver) {
        String driverClass=metadataconnection.getDriverClass();
        if (MetadataConnectionUtils.isDerbyRelatedDb(driverClass,dbType)) {
          derbyDriver=(Driver)list.get(i);
        }
      }
      if (list.get(i) instanceof java.sql.Connection) {
        sqlConn=(java.sql.Connection)list.get(i);
      }
    }
    try {
      if (sqlConn != null) {
        DatabaseMetaData dm=extractMeta.getDatabaseMetaData(sqlConn,dbType,false,metadataconnection.getDatabase());
        MetadataFillFactory.getDBInstance().fillCatalogs(dbConn,dm,MetadataConnectionUtils.getPackageFilter(dbConn,dm,true));
        MetadataFillFactory.getDBInstance().fillSchemas(dbConn,dm,MetadataConnectionUtils.getPackageFilter(dbConn,dm,false));
      }
    }
 catch (    Exception e) {
      ExceptionHandler.process(e);
    }
 finally {
      if (sqlConn != null) {
        ConnectionUtils.closeConnection(sqlConn);
      }
      if (derbyDriver != null) {
        try {
          derbyDriver.connect("String_Node_Str",null);
        }
 catch (        SQLException e) {
        }
      }
    }
  }
}