Program: 126891
Project: 126891
Buggy source:
public List<Package> fillSchemas(Connection dbConn,DatabaseMetaData dbJDBCMetadata,IMetadataConnection metaConnection,List<String> schemaFilter){
  List<Schema> returnSchemas=new ArrayList<Schema>();
  if (dbJDBCMetadata == null || (dbConn != null && ConnectionHelper.getCatalogs(dbConn).size() > 0) || ConnectionUtils.isSybase(dbJDBCMetadata)) {
    return null;
  }
  ResultSet schemas=null;
  if (dbConn != null && EDatabaseTypeName.TERADATA.getProduct().equals(((DatabaseConnection)dbConn).getProductId())) {
    if (!dbConn.isContextMode()) {
      String sid=((DatabaseConnection)dbConn).getSID();
      if (sid != null && sid.length() > 0) {
        schemaFilter.add(sid);
      }
    }
 else {
      IMetadataConnection iMetadataCon=metaConnection;
      if (iMetadataCon == null) {
        iMetadataCon=ConvertionHelper.convert(dbConn);
      }
      String sid=iMetadataCon.getDatabase();
      if (sid != null && sid.length() > 0) {
        schemaFilter.add(sid);
      }
    }
  }
  if (dbConn != null && dbConn.isContextMode()) {
    if (EDatabaseTypeName.ORACLEFORSID.getProduct().equals(((DatabaseConnection)dbConn).getProductId()) || EDatabaseTypeName.IBMDB2.getProduct().equals(((DatabaseConnection)dbConn).getProductId())) {
      IMetadataConnection iMetadataCon=metaConnection;
      if (iMetadataCon == null) {
        iMetadataCon=ConvertionHelper.convert(dbConn);
      }
      if (iMetadataCon != null) {
        String schemaTemp=iMetadataCon.getSchema();
        if ("String_Node_Str".equals(schemaTemp)) {
          schemaFilter.clear();
        }
      }
    }
  }
  try {
    if (dbConn != null && EDatabaseTypeName.ACCESS.getProduct().equals(((DatabaseConnection)dbConn).getProductId())) {
      return null;
    }
    schemas=dbJDBCMetadata.getSchemas();
  }
 catch (  SQLException e) {
    log.warn("String_Node_Str");
  }
  boolean hasSchema=false;
  try {
    boolean isHive2=HiveConnectionManager.getInstance().isHive2(metaConnection);
    if (schemas != null) {
      String schemaName=null;
      while (schemas.next()) {
        if (!ConnectionUtils.isOdbcTeradata(dbJDBCMetadata) && !isHive2) {
          schemaName=schemas.getString(MetaDataConstants.TABLE_SCHEM.name());
          if (schemaName == null) {
            schemaName=schemas.getString(DatabaseConstant.ODBC_ORACLE_SCHEMA_NAME);
          }
          if (schemaName == null) {
            schemaName=schemas.getString(1);
          }
        }
 else {
          schemaName=schemas.getString(1);
        }
        hasSchema=true;
        String uiSchemaOnConnWizard=null;
        if (dbConn != null) {
          uiSchemaOnConnWizard=((DatabaseConnection)dbConn).getUiSchema();
          if (isHive2) {
            uiSchemaOnConnWizard=((DatabaseConnection)dbConn).getSID();
          }
        }
        if ((!isEmptyString(uiSchemaOnConnWizard) || !isNullUiSchema(dbConn)) && dbConn != null) {
          Schema schema=SchemaHelper.createSchema(TalendCWMService.getReadableName(dbConn,uiSchemaOnConnWizard));
          returnSchemas.add(schema);
          break;
        }
 else         if (isCreateElement(schemaFilter,schemaName)) {
          Schema schema=SchemaHelper.createSchema(schemaName);
          returnSchemas.add(schema);
        }
      }
      schemas.close();
    }
  }
 catch (  SQLException e) {
    log.error(e,e);
  }
  if (!hasSchema) {
    Schema schema=SchemaHelper.createSchema("String_Node_Str");
    returnSchemas.add(schema);
  }
  Set<MetadataTable> tableSet=new HashSet<MetadataTable>();
  if (dbConn != null) {
    tableSet.addAll(ConnectionHelper.getTables(dbConn));
  }
  List<Schema> oldSchemas=new ArrayList<Schema>();
  for (  MetadataTable table : tableSet) {
    EObject eContainer=table.eContainer();
    if (eContainer != null && eContainer instanceof Schema && !oldSchemas.contains(eContainer)) {
      oldSchemas.add((Schema)eContainer);
    }
  }
  if (isLinked() && !returnSchemas.isEmpty()) {
    ConnectionHelper.addSchemas(returnSchemas,dbConn);
  }
  for (  Schema schema : oldSchemas) {
    List<Schema> list=new ArrayList<Schema>();
    String name=schema.getName();
    Schema s=(Schema)ConnectionHelper.getPackage(name,dbConn,Schema.class);
    if (s != null) {
      list.add(s);
      ConnectionHelper.removeSchemas(list,dbConn);
      ConnectionHelper.addSchema(schema,dbConn);
    }
 else {
      ConnectionHelper.addSchema(schema,dbConn);
    }
  }
  return ListUtils.castList(Package.class,returnSchemas);
}

Fixed version (ground truth):
public List<Package> fillSchemas(Connection dbConn,DatabaseMetaData dbJDBCMetadata,IMetadataConnection metaConnection,List<String> schemaFilter){
  List<Schema> returnSchemas=new ArrayList<Schema>();
  if (dbJDBCMetadata == null || (dbConn != null && ConnectionHelper.getCatalogs(dbConn).size() > 0) || ConnectionUtils.isSybase(dbJDBCMetadata)) {
    return null;
  }
  ResultSet schemas=null;
  if (dbConn != null && EDatabaseTypeName.TERADATA.getProduct().equals(((DatabaseConnection)dbConn).getProductId())) {
    if (!dbConn.isContextMode()) {
      String sid=((DatabaseConnection)dbConn).getSID();
      if (sid != null && sid.length() > 0) {
        schemaFilter.add(sid);
      }
    }
 else {
      IMetadataConnection iMetadataCon=metaConnection;
      if (iMetadataCon == null) {
        iMetadataCon=ConvertionHelper.convert(dbConn);
      }
      String sid=iMetadataCon.getDatabase();
      if (sid != null && sid.length() > 0) {
        schemaFilter.add(sid);
      }
    }
  }
  if (dbConn != null && dbConn.isContextMode()) {
    if (EDatabaseTypeName.ORACLEFORSID.getProduct().equals(((DatabaseConnection)dbConn).getProductId()) || EDatabaseTypeName.IBMDB2.getProduct().equals(((DatabaseConnection)dbConn).getProductId())) {
      IMetadataConnection iMetadataCon=metaConnection;
      if (iMetadataCon == null) {
        iMetadataCon=ConvertionHelper.convert(dbConn);
      }
      if (iMetadataCon != null) {
        String schemaTemp=iMetadataCon.getSchema();
        if ("String_Node_Str".equals(schemaTemp)) {
          schemaFilter.clear();
        }
      }
    }
  }
  try {
    if (dbConn != null && EDatabaseTypeName.ACCESS.getProduct().equals(((DatabaseConnection)dbConn).getProductId())) {
      return null;
    }
    schemas=dbJDBCMetadata.getSchemas();
  }
 catch (  SQLException e) {
    log.warn("String_Node_Str");
  }
  boolean hasSchema=false;
  try {
    boolean isHive2=HiveConnectionManager.getInstance().isHive2(metaConnection);
    if (schemas != null && !ConnectionUtils.isOdbcHyperFileSQL(dbJDBCMetadata)) {
      String schemaName=null;
      while (schemas.next()) {
        if (!ConnectionUtils.isOdbcTeradata(dbJDBCMetadata) && !isHive2) {
          schemaName=schemas.getString(MetaDataConstants.TABLE_SCHEM.name());
          if (schemaName == null) {
            schemaName=schemas.getString(DatabaseConstant.ODBC_ORACLE_SCHEMA_NAME);
          }
          if (schemaName == null) {
            schemaName=schemas.getString(1);
          }
        }
 else {
          schemaName=schemas.getString(1);
        }
        hasSchema=true;
        String uiSchemaOnConnWizard=null;
        if (dbConn != null) {
          uiSchemaOnConnWizard=((DatabaseConnection)dbConn).getUiSchema();
          if (isHive2) {
            uiSchemaOnConnWizard=((DatabaseConnection)dbConn).getSID();
          }
        }
        if ((!isEmptyString(uiSchemaOnConnWizard) || !isNullUiSchema(dbConn)) && dbConn != null) {
          Schema schema=SchemaHelper.createSchema(TalendCWMService.getReadableName(dbConn,uiSchemaOnConnWizard));
          returnSchemas.add(schema);
          break;
        }
 else         if (isCreateElement(schemaFilter,schemaName)) {
          Schema schema=SchemaHelper.createSchema(schemaName);
          returnSchemas.add(schema);
        }
      }
      schemas.close();
    }
  }
 catch (  SQLException e) {
    log.error(e,e);
  }
  if (!hasSchema) {
    Schema schema=SchemaHelper.createSchema("String_Node_Str");
    returnSchemas.add(schema);
  }
  Set<MetadataTable> tableSet=new HashSet<MetadataTable>();
  if (dbConn != null) {
    tableSet.addAll(ConnectionHelper.getTables(dbConn));
  }
  List<Schema> oldSchemas=new ArrayList<Schema>();
  for (  MetadataTable table : tableSet) {
    EObject eContainer=table.eContainer();
    if (eContainer != null && eContainer instanceof Schema && !oldSchemas.contains(eContainer)) {
      oldSchemas.add((Schema)eContainer);
    }
  }
  if (isLinked() && !returnSchemas.isEmpty()) {
    ConnectionHelper.addSchemas(returnSchemas,dbConn);
  }
  for (  Schema schema : oldSchemas) {
    List<Schema> list=new ArrayList<Schema>();
    String name=schema.getName();
    Schema s=(Schema)ConnectionHelper.getPackage(name,dbConn,Schema.class);
    if (s != null) {
      list.add(s);
      ConnectionHelper.removeSchemas(list,dbConn);
      ConnectionHelper.addSchema(schema,dbConn);
    }
 else {
      ConnectionHelper.addSchema(schema,dbConn);
    }
  }
  return ListUtils.castList(Package.class,returnSchemas);
}