Program: 138640
Project: 138640
Buggy source:
/** 
 * Method "getSchemas" returns a map of catalogs to schemas. Warning: if no catalog is found, catalog name (i.e. key of the map) can be null.
 * @param connection the connection
 * @return a map [catalog's name -> list of Schemas ].
 * @throws SQLException
 */
public static Map<String,List<Schema>> getSchemas(java.sql.Connection connection) throws SQLException {
  Map<String,List<Schema>> catalogName2schemas=new HashMap<String,List<Schema>>();
  DatabaseMetaData connectionMetadata=getConnectionMetadata(connection);
  final List<String> catalogNames=new ArrayList<String>();
  fillListOfCatalogs(connection,catalogNames);
  boolean odbcMssqlFlag=ConnectionUtils.isOdbcMssql(connection);
  boolean postgresqlFlag=ConnectionUtils.isPostgresql(connection);
  ResultSet schemas=null;
  try {
    schemas=connectionMetadata.getSchemas();
  }
 catch (  Exception e1) {
    log.warn("String_Node_Str",e1);
  }
  try {
    if (schemas != null) {
      final int columnCount=schemas.getMetaData() == null ? 0 : schemas.getMetaData().getColumnCount();
      boolean hasSchema=false;
      while (schemas.next()) {
        String catName=null;
        String schemaName=null;
        if (columnCount > 1) {
          try {
            catName=schemas.getString(MetaDataConstants.TABLE_CATALOG.name());
          }
 catch (          Exception e) {
            log.warn("String_Node_Str",e);
          }
          try {
            schemaName=schemas.getString(MetaDataConstants.TABLE_SCHEM.name());
          }
 catch (          Exception e) {
            log.warn(e,e);
          }
          if (schemaName == null) {
            try {
              schemaName=schemas.getString(DatabaseConstant.ODBC_ORACLE_SCHEMA_NAME);
            }
 catch (            Exception e) {
              log.warn(e,e);
            }
          }
          if (schemaName == null) {
            try {
              schemaName=schemas.getString(1);
            }
 catch (            Exception e) {
              log.warn(e,e);
            }
          }
          if (catName != null) {
            createSchema(schemaName,catName,catalogName2schemas);
          }
        }
        if (odbcMssqlFlag || postgresqlFlag) {
          try {
            schemaName=schemas.getString(1);
          }
 catch (          Exception e) {
            log.warn(e,e);
          }
        }
        if (catName == null) {
          if (catalogNames.isEmpty()) {
            if (schemaName == null) {
              schemaName=getSchemaName(schemas);
            }
            createSchema(schemaName,null,catalogName2schemas);
          }
 else {
            for (            String catalogName : catalogNames) {
              createSchema(schemaName,catalogName,catalogName2schemas);
            }
          }
        }
        hasSchema=true;
      }
      if (!hasSchema && catalogName2schemas.isEmpty() && catalogNames.isEmpty()) {
        Schema schema=createSchema("String_Node_Str");
        MultiMapHelper.addUniqueObjectToListMap(null,schema,catalogName2schemas);
      }
    }
  }
 catch (  SQLException e) {
    throw e;
  }
 finally {
    if (schemas != null) {
      schemas.close();
    }
  }
  return catalogName2schemas;
}

Fixed version (ground truth):
/** 
 * Method "getSchemas" returns a map of catalogs to schemas. Warning: if no catalog is found, catalog name (i.e. key of the map) can be null.
 * @param connection the connection
 * @return a map [catalog's name -> list of Schemas ].
 * @throws SQLException
 */
public static Map<String,List<Schema>> getSchemas(java.sql.Connection connection) throws SQLException {
  Map<String,List<Schema>> catalogName2schemas=new HashMap<String,List<Schema>>();
  DatabaseMetaData connectionMetadata=getConnectionMetadata(connection);
  final List<String> catalogNames=new ArrayList<String>();
  fillListOfCatalogs(connection,catalogNames);
  boolean odbcMssqlFlag=ConnectionUtils.isOdbcMssql(connection);
  boolean postgresqlFlag=ConnectionUtils.isPostgresql(connection);
  boolean odbcProgressFlag=ConnectionUtils.isOdbcProgress(connection);
  ResultSet schemas=null;
  try {
    schemas=connectionMetadata.getSchemas();
  }
 catch (  Exception e1) {
    log.warn("String_Node_Str",e1);
  }
  try {
    if (schemas != null) {
      final int columnCount=schemas.getMetaData() == null ? 0 : schemas.getMetaData().getColumnCount();
      boolean hasSchema=false;
      while (schemas.next()) {
        String catName=null;
        String schemaName=null;
        if (columnCount > 1) {
          try {
            catName=schemas.getString(MetaDataConstants.TABLE_CATALOG.name());
          }
 catch (          Exception e) {
            log.warn("String_Node_Str",e);
          }
          try {
            schemaName=schemas.getString(MetaDataConstants.TABLE_SCHEM.name());
          }
 catch (          Exception e) {
            log.warn(e,e);
          }
          if (schemaName == null) {
            try {
              schemaName=schemas.getString(DatabaseConstant.ODBC_ORACLE_SCHEMA_NAME);
            }
 catch (            Exception e) {
              log.warn(e,e);
            }
          }
          if (schemaName == null) {
            try {
              schemaName=schemas.getString(1);
            }
 catch (            Exception e) {
              log.warn(e,e);
            }
          }
          if (catName != null) {
            createSchema(schemaName,catName,catalogName2schemas);
          }
        }
        if (odbcMssqlFlag || postgresqlFlag || odbcProgressFlag) {
          try {
            schemaName=schemas.getString(1);
          }
 catch (          Exception e) {
            log.warn(e,e);
          }
        }
        if (catName == null) {
          if (catalogNames.isEmpty()) {
            if (schemaName == null) {
              schemaName=getSchemaName(schemas);
            }
            createSchema(schemaName,null,catalogName2schemas);
          }
 else {
            for (            String catalogName : catalogNames) {
              createSchema(schemaName,catalogName,catalogName2schemas);
            }
          }
        }
        hasSchema=true;
      }
      if (!hasSchema && catalogName2schemas.isEmpty() && catalogNames.isEmpty()) {
        Schema schema=createSchema("String_Node_Str");
        MultiMapHelper.addUniqueObjectToListMap(null,schema,catalogName2schemas);
      }
    }
  }
 catch (  SQLException e) {
    throw e;
  }
 finally {
    if (schemas != null) {
      schemas.close();
    }
  }
  return catalogName2schemas;
}