Program: 129303
Project: 129303
Buggy source:
public List<Schema> fillSchemaToCatalog(Connection dbConn,DatabaseMetaData dbJDBCMetadata,Catalog catalog,List<String> schemaFilter) throws Throwable {
  ResultSet schemaRs=null;
  try {
    if (dbJDBCMetadata.getDriverName().equals(DatabaseConstant.MSSQL_DRIVER_NAME_JDBC2_0)) {
      Method getSchemaMethod=dbJDBCMetadata.getClass().getMethod("String_Node_Str",String.class,String.class);
      schemaRs=(ResultSet)getSchemaMethod.invoke(dbJDBCMetadata,catalog.getName(),null);
    }
  }
 catch (  SecurityException e) {
  }
catch (  NoSuchMethodException e) {
  }
catch (  IllegalArgumentException e) {
  }
catch (  IllegalAccessException e) {
  }
catch (  InvocationTargetException e) {
    if (e.getTargetException().getClass().toString().equals(SQLServerException.class.toString())) {
      throw e.getTargetException();
    }
  }
catch (  SQLException e) {
    log.error(e,e);
  }
  if (schemaRs == null) {
    try {
      schemaRs=dbJDBCMetadata.getSchemas();
    }
 catch (    SQLException e) {
      if (log.isDebugEnabled()) {
        log.debug(e,e);
      }
    }
  }
  List<String> schemaNameCacheTmp=new ArrayList<String>();
  List<Schema> schemaList=new ArrayList<Schema>();
  try {
    while (schemaRs.next()) {
      String schemaName=null;
      String catalogName=null;
      try {
        schemaName=schemaRs.getString(MetaDataConstants.TABLE_SCHEM.name());
        if (!MetadataConnectionUtils.isPostgresql(dbJDBCMetadata)) {
          catalogName=schemaRs.getString(MetaDataConstants.TABLE_CATALOG.name());
        }
        if (MetadataConnectionUtils.isMssql(dbJDBCMetadata) && dbJDBCMetadata.getDatabaseMajorVersion() > 8 && dbJDBCMetadata.getDriverMajorVersion() > 1) {
          if (catalogName != null && catalogName != schemaName) {
            schemaName=catalogName;
          }
        }
        if (schemaName == null || !MetadataConnectionUtils.isMssql(dbJDBCMetadata.getConnection()) && catalogName != null && !catalogName.equals(catalog.getName())) {
          continue;
        }
      }
 catch (      Exception e) {
      }
      if (!schemaNameCacheTmp.contains(schemaName) && !MetadataConnectionUtils.isMysql(dbJDBCMetadata)) {
        schemaNameCacheTmp.add(schemaName);
        Schema schema=SchemaHelper.createSchema(schemaName);
        if (!filterMetadaElement(schemaFilter,schemaName)) {
          continue;
        }
        schemaList.add(schema);
      }
    }
    schemaRs.close();
  }
 catch (  Exception e) {
    if (log.isDebugEnabled()) {
      log.debug(e,e);
    }
  }
  return schemaList;
}

Fixed version (ground truth):
public List<Schema> fillSchemaToCatalog(Connection dbConn,DatabaseMetaData dbJDBCMetadata,Catalog catalog,List<String> schemaFilter) throws Throwable {
  ResultSet schemaRs=null;
  try {
    if (dbJDBCMetadata.getDriverName().equals(DatabaseConstant.MSSQL_DRIVER_NAME_JDBC2_0)) {
      Method getSchemaMethod=dbJDBCMetadata.getClass().getMethod("String_Node_Str",String.class,String.class);
      schemaRs=(ResultSet)getSchemaMethod.invoke(dbJDBCMetadata,catalog.getName(),null);
    }
  }
 catch (  SecurityException e) {
  }
catch (  NoSuchMethodException e) {
  }
catch (  IllegalArgumentException e) {
  }
catch (  IllegalAccessException e) {
  }
catch (  InvocationTargetException e) {
    if (e.getTargetException().getClass().toString().equals("String_Node_Str")) {
      throw e.getTargetException();
    }
  }
catch (  SQLException e) {
    log.error(e,e);
  }
  if (schemaRs == null) {
    try {
      schemaRs=dbJDBCMetadata.getSchemas();
    }
 catch (    SQLException e) {
      if (log.isDebugEnabled()) {
        log.debug(e,e);
      }
    }
  }
  List<String> schemaNameCacheTmp=new ArrayList<String>();
  List<Schema> schemaList=new ArrayList<Schema>();
  try {
    while (schemaRs.next()) {
      String schemaName=null;
      String catalogName=null;
      try {
        schemaName=schemaRs.getString(MetaDataConstants.TABLE_SCHEM.name());
        if (!MetadataConnectionUtils.isPostgresql(dbJDBCMetadata)) {
          catalogName=schemaRs.getString(MetaDataConstants.TABLE_CATALOG.name());
        }
        if (MetadataConnectionUtils.isMssql(dbJDBCMetadata) && dbJDBCMetadata.getDatabaseMajorVersion() > 8 && dbJDBCMetadata.getDriverMajorVersion() > 1) {
          if (catalogName != null && catalogName != schemaName) {
            schemaName=catalogName;
          }
        }
        if (schemaName == null || !MetadataConnectionUtils.isMssql(dbJDBCMetadata.getConnection()) && catalogName != null && !catalogName.equals(catalog.getName())) {
          continue;
        }
      }
 catch (      Exception e) {
      }
      if (!schemaNameCacheTmp.contains(schemaName) && !MetadataConnectionUtils.isMysql(dbJDBCMetadata)) {
        schemaNameCacheTmp.add(schemaName);
        Schema schema=SchemaHelper.createSchema(schemaName);
        if (!filterMetadaElement(schemaFilter,schemaName)) {
          continue;
        }
        schemaList.add(schema);
      }
    }
    schemaRs.close();
  }
 catch (  Exception e) {
    if (log.isDebugEnabled()) {
      log.debug(e,e);
    }
  }
  return schemaList;
}