Program: 129932
Project: 129932
Buggy source:
public List<Package> fillSchemas(Connection dbConn,DatabaseMetaData dbJDBCMetadata,List<String> schemaFilter){
  List<Schema> returnSchemas=new ArrayList<Schema>();
  if (dbJDBCMetadata == null || (dbConn != null && ConnectionHelper.getCatalogs(dbConn).size() > 0)) {
    return null;
  }
  ResultSet schemas=null;
  if (dbConn != null && EDatabaseTypeName.TERADATA.getProduct().equals(((DatabaseConnection)dbConn).getProductId())) {
    String sid=((DatabaseConnection)dbConn).getSID();
    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=ConvertionHelper.convert((DatabaseConnection)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.error("String_Node_Str");
    return null;
  }
  try {
    if (schemas != null) {
      boolean hasSchema=false;
      String schemaName=null;
      while (schemas.next()) {
        if (!ConnectionUtils.isOdbcTeradata(dbJDBCMetadata)) {
          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;
        if (!filterMetadaElement(schemaFilter,schemaName)) {
          continue;
        }
        Schema schema=SchemaHelper.createSchema(schemaName);
        returnSchemas.add(schema);
      }
      schemas.close();
      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);
        }
      }
    }
  }
 catch (  SQLException e) {
    log.error(e,e);
  }
  return ListUtils.castList(Package.class,returnSchemas);
}

Fixed version (ground truth):
public List<Package> fillSchemas(Connection dbConn,DatabaseMetaData dbJDBCMetadata,List<String> schemaFilter){
  List<Schema> returnSchemas=new ArrayList<Schema>();
  if (dbJDBCMetadata == null || (dbConn != null && ConnectionHelper.getCatalogs(dbConn).size() > 0)) {
    return null;
  }
  ResultSet schemas=null;
  if (dbConn != null && EDatabaseTypeName.TERADATA.getProduct().equals(((DatabaseConnection)dbConn).getProductId())) {
    String sid=((DatabaseConnection)dbConn).getSID();
    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=ConvertionHelper.convert((DatabaseConnection)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 {
    if (schemas != null) {
      String schemaName=null;
      while (schemas.next()) {
        if (!ConnectionUtils.isOdbcTeradata(dbJDBCMetadata)) {
          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;
        if (!filterMetadaElement(schemaFilter,schemaName)) {
          continue;
        }
        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);
}