Program: 125903
Project: 125903
Buggy source:
private void fillDefaultValues(DatabaseConnection connection){
  String distribution=connection.getParameters().get(ConnParameterKeys.CONN_PARA_KEY_HIVE_DISTRIBUTION);
  String version=connection.getParameters().get(ConnParameterKeys.CONN_PARA_KEY_HIVE_VERSION);
  String[] hiveModesDisplay=HiveMetadataHelper.getHiveModesDisplay(distribution,version,false);
  HiveModeInfo hiveMode=HiveModeInfo.getByDisplay(hiveModesDisplay[0]);
  boolean isEmbeddedMode=(hiveMode == HiveModeInfo.EMBEDDED);
  connection.getParameters().put(ConnParameterKeys.CONN_PARA_KEY_HIVE_MODE,hiveMode.getName());
  String[] hiveServersDisplay=HiveMetadataHelper.getHiveServersDisplay(distribution,version,hiveMode.getName(),false);
  HiveServerVersionInfo server=HiveServerVersionInfo.getByDisplay(hiveServersDisplay[0]);
  String hiveServer=server.getKey();
  connection.getParameters().put(ConnParameterKeys.HIVE_SERVER_VERSION,hiveServer);
  if (StringUtils.isEmpty(connection.getSID())) {
    String defaultDatabase=HadoopDefaultConfsManager.getInstance().getDefaultConfValue(distribution,EHadoopCategory.HIVE.getName(),EHadoopProperties.DATABASE.getName());
    if (StringUtils.isNotEmpty(defaultDatabase)) {
      connection.setSID(defaultDatabase);
    }
  }
  if (StringUtils.isEmpty(connection.getPort())) {
    String defaultPort=null;
    if (isEmbeddedMode) {
      defaultPort=HadoopDefaultConfsManager.getInstance().getDefaultConfValue(distribution,EHadoopCategory.HIVE.getName(),HiveModeInfo.EMBEDDED.getName(),EHadoopProperties.PORT.getName());
    }
 else {
      defaultPort=HadoopDefaultConfsManager.getInstance().getDefaultConfValue(distribution,EHadoopCategory.HIVE.getName(),HiveModeInfo.STANDALONE.getName(),EHadoopProperties.PORT.getName());
    }
    if (StringUtils.isNotEmpty(defaultPort)) {
      connection.setPort(defaultPort);
    }
  }
  if (StringUtils.isEmpty(connection.getURL())) {
    String template=null;
    if (HiveServerVersionInfo.HIVE_SERVER_2.getKey().equals(hiveServer)) {
      template=DbConnStrForHive.URL_HIVE_2_TEMPLATE;
    }
 else {
      template=DbConnStrForHive.URL_HIVE_1_TEMPLATE;
    }
    String url=DatabaseConnStrUtil.getHiveURLString(connection,connection.getServerName(),connection.getPort(),connection.getSID(),template);
    if (StringUtils.isNotEmpty(url)) {
      connection.setURL(url);
    }
  }
}

Fixed version (ground truth):
private void fillDefaultValues(DatabaseConnection connection){
  String distribution=connection.getParameters().get(ConnParameterKeys.CONN_PARA_KEY_HIVE_DISTRIBUTION);
  String version=connection.getParameters().get(ConnParameterKeys.CONN_PARA_KEY_HIVE_VERSION);
  String[] hiveServersDisplay=HiveMetadataHelper.getHiveServersDisplay(distribution,version,false);
  if (hiveServersDisplay == null || hiveServersDisplay.length == 0) {
    return;
  }
  HiveServerVersionInfo server=HiveServerVersionInfo.getByDisplay(hiveServersDisplay[0]);
  String hiveServer=server.getKey();
  connection.getParameters().put(ConnParameterKeys.HIVE_SERVER_VERSION,hiveServer);
  String[] hiveModesDisplay=HiveMetadataHelper.getHiveModesDisplay(distribution,version,hiveServer,false);
  if (hiveModesDisplay == null || hiveModesDisplay.length == 0) {
    return;
  }
  HiveModeInfo hiveMode=HiveModeInfo.getByDisplay(hiveModesDisplay[0]);
  boolean isEmbeddedMode=(hiveMode == HiveModeInfo.EMBEDDED);
  connection.getParameters().put(ConnParameterKeys.CONN_PARA_KEY_HIVE_MODE,hiveMode.getName());
  if (StringUtils.isEmpty(connection.getSID())) {
    String defaultDatabase=HadoopDefaultConfsManager.getInstance().getDefaultConfValue(distribution,EHadoopCategory.HIVE.getName(),EHadoopProperties.DATABASE.getName());
    if (StringUtils.isNotEmpty(defaultDatabase)) {
      connection.setSID(defaultDatabase);
    }
  }
  if (StringUtils.isEmpty(connection.getPort())) {
    String defaultPort=null;
    if (isEmbeddedMode) {
      defaultPort=HadoopDefaultConfsManager.getInstance().getDefaultConfValue(distribution,EHadoopCategory.HIVE.getName(),HiveModeInfo.EMBEDDED.getName(),EHadoopProperties.PORT.getName());
    }
 else {
      defaultPort=HadoopDefaultConfsManager.getInstance().getDefaultConfValue(distribution,EHadoopCategory.HIVE.getName(),HiveModeInfo.STANDALONE.getName(),EHadoopProperties.PORT.getName());
    }
    if (StringUtils.isNotEmpty(defaultPort)) {
      connection.setPort(defaultPort);
    }
  }
  if (StringUtils.isEmpty(connection.getURL())) {
    String template=null;
    if (HiveServerVersionInfo.HIVE_SERVER_2.getKey().equals(hiveServer)) {
      template=DbConnStrForHive.URL_HIVE_2_TEMPLATE;
    }
 else {
      template=DbConnStrForHive.URL_HIVE_1_TEMPLATE;
    }
    String url=DatabaseConnStrUtil.getHiveURLString(connection,connection.getServerName(),connection.getPort(),connection.getSID(),template);
    if (StringUtils.isNotEmpty(url)) {
      connection.setURL(url);
    }
  }
}