Program: 137634
Project: 137634
Buggy source:
/** 
 * This method is used to check conectiton is avalible for analysis or report ,when analysis or report runs.
 * @param analysisDataProvider
 * @return
 */
public static ReturnCode isConnectionAvailable(Connection analysisDataProvider){
  ReturnCode returnCode=new ReturnCode();
  IMetadataConnection metadataConnection=ConvertionHelper.convert(analysisDataProvider);
  if (metadataConnection != null) {
    if (EDatabaseTypeName.HIVE.getXmlName().equalsIgnoreCase(metadataConnection.getDbType())) {
      try {
        HiveConnectionManager.getInstance().checkConnection(metadataConnection);
        returnCode.setOk(true);
        return returnCode;
      }
 catch (      ClassNotFoundException e) {
        returnCode.setOk(false);
        returnCode.setMessage(e.toString());
        return returnCode;
      }
catch (      InstantiationException e) {
        returnCode.setOk(false);
        returnCode.setMessage(e.toString());
        return returnCode;
      }
catch (      IllegalAccessException e) {
        returnCode.setOk(false);
        returnCode.setMessage(e.toString());
        return returnCode;
      }
catch (      SQLException e) {
        returnCode.setOk(false);
        returnCode.setMessage(e.toString());
        return returnCode;
      }
    }
  }
  if (analysisDataProvider instanceof FileConnection) {
    FileConnection fileConn=(FileConnection)analysisDataProvider;
    if (fileConn.isContextMode()) {
      fileConn=getOriginalFileConnection(fileConn);
    }
    String filePath=fileConn.getFilePath();
    try {
      BufferedReader filePathAvalible=FileConnectionContextUtils.isFilePathAvailable(filePath,fileConn);
      if (filePathAvalible != null) {
        returnCode.setOk(true);
        return returnCode;
      }
    }
 catch (    UnsupportedEncodingException e) {
      returnCode.setOk(false);
      returnCode.setMessage(filePath);
      return returnCode;
    }
catch (    FileNotFoundException e) {
      returnCode.setOk(false);
      returnCode.setMessage(filePath);
      return returnCode;
    }
catch (    IOException e) {
      returnCode.setOk(false);
      returnCode.setMessage(filePath);
      return returnCode;
    }
  }
  Properties props=new Properties();
  String userName=JavaSqlFactory.getUsername(analysisDataProvider);
  String password=JavaSqlFactory.getPassword(analysisDataProvider);
  String url=JavaSqlFactory.getURL(analysisDataProvider);
  props.put(TaggedValueHelper.USER,userName);
  props.put(TaggedValueHelper.PASSWORD,password);
  if (analysisDataProvider instanceof MDMConnection) {
    props.put(TaggedValueHelper.UNIVERSE,ConnectionHelper.getUniverse((MDMConnection)analysisDataProvider));
    props.put(TaggedValueHelper.DATA_FILTER,ConnectionHelper.getDataFilter((MDMConnection)analysisDataProvider));
    MdmWebserviceConnection mdmWebserviceConnection=new MdmWebserviceConnection(JavaSqlFactory.getURL(analysisDataProvider),props);
    returnCode=mdmWebserviceConnection.checkDatabaseConnection();
    return returnCode;
  }
 else   if (isGeneralJdbc(analysisDataProvider)) {
    ReturnCode rcJdbc=checkGeneralJdbcJarFilePathDriverClassName((DatabaseConnection)analysisDataProvider);
    if (!rcJdbc.isOk()) {
      return rcJdbc;
    }
  }
 else   if (analysisDataProvider instanceof DatabaseConnection) {
    DatabaseConnection dbConn=(DatabaseConnection)analysisDataProvider;
    String databaseType=dbConn.getDatabaseType();
    String dbVersionString=dbConn.getDbVersionString();
    if (databaseType != null) {
      props.put(TaggedValueHelper.DBTYPE,dbConn.getDatabaseType());
    }
    if (dbVersionString != null) {
      props.put(TaggedValueHelper.DB_PRODUCT_VERSION,dbVersionString);
    }
  }
  if (isHiveEmbedded(analysisDataProvider)) {
    JavaSqlFactory.doHivePreSetup(analysisDataProvider);
  }
  returnCode=ConnectionUtils.checkConnection(url,JavaSqlFactory.getDriverClass(analysisDataProvider),props);
  return returnCode;
}

Fixed version (ground truth):
/** 
 * This method is used to check conectiton is avalible for analysis or report ,when analysis or report runs.
 * @param analysisDataProvider
 * @return
 */
public static ReturnCode isConnectionAvailable(Connection analysisDataProvider){
  ReturnCode returnCode=new ReturnCode();
  IMetadataConnection metadataConnection=ConvertionHelper.convert(analysisDataProvider);
  if (metadataConnection != null) {
    if (EDatabaseTypeName.HIVE.getXmlName().equalsIgnoreCase(metadataConnection.getDbType())) {
      try {
        HiveConnectionManager.getInstance().checkConnection(metadataConnection);
        returnCode.setOk(true);
        return returnCode;
      }
 catch (      ClassNotFoundException e) {
        returnCode.setOk(false);
        returnCode.setMessage(e.toString());
        return returnCode;
      }
catch (      InstantiationException e) {
        returnCode.setOk(false);
        returnCode.setMessage(e.toString());
        return returnCode;
      }
catch (      IllegalAccessException e) {
        returnCode.setOk(false);
        returnCode.setMessage(e.toString());
        return returnCode;
      }
catch (      SQLException e) {
        returnCode.setOk(false);
        returnCode.setMessage(e.toString());
        return returnCode;
      }
    }
  }
  if (analysisDataProvider instanceof FileConnection) {
    FileConnection fileConn=(FileConnection)analysisDataProvider;
    if (fileConn.isContextMode()) {
      IRepositoryContextService service=CoreRuntimePlugin.getInstance().getRepositoryContextService();
      if (service != null) {
        fileConn=service.cloneOriginalValueConnection(fileConn);
      }
    }
    String filePath=fileConn.getFilePath();
    try {
      BufferedReader filePathAvalible=FilesUtils.isFilePathAvailable(filePath,fileConn);
      if (filePathAvalible != null) {
        returnCode.setOk(true);
        return returnCode;
      }
    }
 catch (    UnsupportedEncodingException e) {
      returnCode.setOk(false);
      returnCode.setMessage(filePath);
      return returnCode;
    }
catch (    FileNotFoundException e) {
      returnCode.setOk(false);
      returnCode.setMessage(filePath);
      return returnCode;
    }
catch (    IOException e) {
      returnCode.setOk(false);
      returnCode.setMessage(filePath);
      return returnCode;
    }
  }
  Properties props=new Properties();
  String userName=JavaSqlFactory.getUsername(analysisDataProvider);
  String password=JavaSqlFactory.getPassword(analysisDataProvider);
  String url=JavaSqlFactory.getURL(analysisDataProvider);
  props.put(TaggedValueHelper.USER,userName);
  props.put(TaggedValueHelper.PASSWORD,password);
  if (analysisDataProvider instanceof MDMConnection) {
    props.put(TaggedValueHelper.UNIVERSE,ConnectionHelper.getUniverse((MDMConnection)analysisDataProvider));
    props.put(TaggedValueHelper.DATA_FILTER,ConnectionHelper.getDataFilter((MDMConnection)analysisDataProvider));
    MdmWebserviceConnection mdmWebserviceConnection=new MdmWebserviceConnection(JavaSqlFactory.getURL(analysisDataProvider),props);
    returnCode=mdmWebserviceConnection.checkDatabaseConnection();
    return returnCode;
  }
 else   if (isGeneralJdbc(analysisDataProvider)) {
    ReturnCode rcJdbc=checkGeneralJdbcJarFilePathDriverClassName((DatabaseConnection)analysisDataProvider);
    if (!rcJdbc.isOk()) {
      return rcJdbc;
    }
  }
 else   if (analysisDataProvider instanceof DatabaseConnection) {
    DatabaseConnection dbConn=(DatabaseConnection)analysisDataProvider;
    String databaseType=dbConn.getDatabaseType();
    String dbVersionString=dbConn.getDbVersionString();
    if (databaseType != null) {
      props.put(TaggedValueHelper.DBTYPE,dbConn.getDatabaseType());
    }
    if (dbVersionString != null) {
      props.put(TaggedValueHelper.DB_PRODUCT_VERSION,dbVersionString);
    }
  }
  if (isHiveEmbedded(analysisDataProvider)) {
    JavaSqlFactory.doHivePreSetup(analysisDataProvider);
  }
  returnCode=ConnectionUtils.checkConnection(url,JavaSqlFactory.getDriverClass(analysisDataProvider),props);
  return returnCode;
}